Puppet User and Group Configuration Example


1) Create a user

node “UT-9c8e99e3959e”{
        user { ‘john’:
        ensure   => ‘present’,
        managehome => true,
        password => ‘$6$gQtfKwwf$riyyLGkm2EtsUjkG03SPhE/PfcrmqDaTrZ1kayHao8s3J1xr8WuC3gWdceFu1RGfCOslh5jSDy8x4xeVx3xYc/’
        }
}

Example:

generic@UT-9c8e99e3959e:~$ cat /etc/passwd | grep john
generic@UT-9c8e99e3959e:~$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1362628656’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/User[john]/ensure: created
notice: Finished catalog run in 0.72 seconds
generic@UT-9c8e99e3959e:~$ cat /etc/passwd | grep john
john:x:1002:1002::/home/john:/bin/sh
generic@UT-9c8e99e3959e:~$ su – john
Password:
$ pwd
/home/john

2) Remove a user

node “UT-9c8e99e3959e”{
        user { ‘john’:
        ensure   => ‘absent’,
        }
}

Example:

generic@UT-9c8e99e3959e:~$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1362628848’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/User[john]/ensure: removed
notice: Finished catalog run in 0.68 seconds
generic@UT-9c8e99e3959e:~$ cat /etc/passwd | grep john
generic@UT-9c8e99e3959e:~$

3) Create a group

node “UT-9c8e99e3959e”{
        group { ‘contractors’:
        ensure   => ‘present’,
        }
}

Example:

generic@UT-9c8e99e3959e:~$ cat /etc/group | grep contractors
generic@UT-9c8e99e3959e:~$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1362629875’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/Group[contractors]/ensure: created
notice: Finished catalog run in 0.33 seconds
generic@UT-9c8e99e3959e:/etc$ cat /etc/group | grep contractors
contractors:x:1002:

4) Remove a group

node “UT-9c8e99e3959e”{
        group { ‘contractors’:
        ensure   => ‘absent’,
        }
}

Example:

generic@UT-9c8e99e3959e:/etc$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1362630224’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/Group[contractors]/ensure: removed
notice: Finished catalog run in 0.34 seconds
generic@UT-9c8e99e3959e:/etc$ cat /etc/group | grep contractors
generic@UT-9c8e99e3959e:/etc$

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s