Creating user accounts with Puppet?

17,311

Solution 1

You can name your classes as you want, but you need to use the right name for resources. In this case, the resource you want to use is user.

There is a very simple way to know how a resource should look:

$ puppet resource user dawud
user { 'dawud':
  ensure  => 'present',
  comment => 'David Sastre Medina,,,',
  gid     => '1001',
  groups  => ['sudo', 'audio', 'src', 'video', 'libvirt'],
  home    => '/home/dawud',
  shell   => '/bin/bash',
  uid     => '1001',
}

That code, inside a class would look:

class foo {
   user { 'dawud':
      ensure  => 'present',
      comment => 'David Sastre Medina,,,',
      gid     => '1001',
      groups  => ['sudo', 'audio', 'src', 'video', 'libvirt'],
      home    => '/home/dawud',
      shell   => '/bin/bash',
      uid     => '1001',
    }
}

Puppetlabs have a very good documentation on the resource abstraction layer, RAL for short.

Solution 2

I'm no puppet whiz, but you have an unmatched { in your sample. You have one open brace for class and another for account, but you only ever close the account brace.

Share:
17,311

Related videos on Youtube

dannymcc
Author by

dannymcc

Updated on September 18, 2022

Comments

  • dannymcc
    dannymcc almost 2 years

    I'm just getting started with Puppet and I have the following code in my test site.pp file:

    class { 'account': {
      'danny':
         home_dir => '/home/danny',
         groups   => [ 'sudo', 'users' ],
         password => 'password'
      }
    }
    

    I'm trying to use the account module from Puppet Forge. I have checked that the module is installed correctly.

    The error given when using the above code is:

    Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not parse for environment production: Syntax error at '{'; expected '}' at /etc/puppet/manifests/site.pp:12 on node testpuppet.domain.io Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run

    Line 12 of site.pp is:

    class { 'account': {
    

    The documentation gives the following example:

    account { 
      'sysadmin':
        home_dir => '/opt/sysadmin',
        groups   => [ 'sudo', 'users' ],
        ssh_key  => 'AAAAB3NzaC1yc2EAAAABIwAAAQEArfQmMkvtWRnwas3DIti9qAuSFQXKcE0kdp5f42PP8l2kTytJPPWp5T/q8PXDQ2d2X5KplMCMDiUQkchqhmDp840jsqBQ9iZPejAjv3w2kITgScFNymAcErtzX52iw4lnUyjZzomCW8G3YthQMaRm2NkI4wcVcjzq+SKyTfzrBoH21RgZlfcx+/50AFRrarpYqel9W5DuLmmShHxD8clPS532Z/1X+1jCW2KikUhdo98lxYTIgFno05lwFOS9Ry89UyBarn1Ecp1zXpIBE7dMQif3UyLUTU9zCVIoZiJj4iO5lemSSV0v8GL97qclBUVJpaCpc4ebR7bhi0nQ28RcxQ==',
        comment   => 'SysAdmin user',
    }
    

    all the other modules that I'm using are within a class, such as the NTP module:

    class { 
      '::ntp': 
      servers => [ 
        '0.uk.pool.ntp.org', 
        '1.uk.pool.ntp.org', 
        '2.uk.pool.ntp.org', 
        '3.uk.pool.ntp.org' 
      ], 
    }
    

    What would the correct syntax be to use the account module?