I have written the following snippet below using user
resource in puppet
to create unix
users .
node 'node2.example.com','node3.example.com'{
user {
'askar':
ensure => 'present',
managehome => 'true',
comment => 'man Home',
home => '/home/askar',
shell => '/bin/bash',
expiry => '2016-03-22',
password => '$1$cs1j/t.D$4Q2Ocr0pulyNTUx/',
password_min_age => '30',
password_max_age => '60',
}
exec {
'chage':
path => '/usr/bin/',
command => 'chage -d 0 askar',
}
}
It works fine for me, but the issue for me, I need to create 10 to 20 users. How can i reuse the above snippet to create 10 users. I am new to puppet
, so pointers will be of great help.
You'll need to refactor your code to use a
define
, which you then reference from your node declarations.modules/myuser/init.pp
manifests/site.pp
Reference: https://docs.puppetlabs.com/puppet/latest/reference/lang_defined_types.html
Alternatively, you use use one of the many modules on the Puppet Forge to accomplish this. Personally, I use this one.