0

When I add a user to my puppet configuration, I end up copy/pasting something like this:

user {'jeff':
  ensure     => 'present',
  groups     => ['sudo', 'supervisor'],
  require    => [Group['sudo'], Group['supervisor']],
  home       => '/home/jeff',
  managehome => true,
  password => '...',
 shell      => '/bin/bash',
}
ssh_authorized_key { 'jeff@lorax':
  ensure  => 'present',
  user    => 'jeff',
  require => User['jeff'],
  type    => 'rsa',
  key     => '...',
}

The only thing that changes from user to user is the user name, the ssh key (tag and value, and some users have several), and sometimes the group set.

I feel quite sure I've missed something about how to do this better, but I haven't found it yet. Any pointers?

jma
  • 425
  • 6
  • 16

1 Answers1

1

You can use one of many community-contributed modules to remove this duplication. For example, using the torrancew/account module (full disclosure: I am not the module owner):

account { 'jeff':
    groups       => ['sudo','supervisor' ],
    ssh_key      => '...',
    password     => '...',
    require      => Group['sudo','supervisor'],
}

Options documentation: GitHub

Craig Watson
  • 9,575
  • 3
  • 32
  • 47
  • That helps a bit, but it would be really nice not to repeat so much boilerplate. `account { 'jeff': home_dir => ..., groups => '...', password => '...', ssh_key => '...' }` and it figures out the rest from there based on some defaults (e.g., in hiera). – jma Sep 23 '15 at 10:04
  • You don't actually need much of the boilerplate stuff, if you take a look through the module documentation, it defaults a lot of things - I've edited my answer to remove the redeclared defaults. – Craig Watson Sep 23 '15 at 10:12