It has been a while since I wrote something on this blog(Not that
there are people expecting something in here). However, it is mostly for my
reference. Puppet is something which I am interested in learning and making
amends since sometime to learn it. I did some learning and later dropped it
like many other my learning projects.
So, I learnt how to create Users and Home directories.
As usual I have revise the basics.
The resources are manifests, can be a USER, SOFTWARE, SERVICE etc.
They have to be defined in the manifests folder of their own for their better
manageability.
/etc/puppet/modules
root@ubuntu:/etc/puppet/modules# ls -l
drwxr-xr-x 3 root root 4096 Jun 9 19:25 homedirs
drwxr-xr-x 3 root root 4096 Jun 9 19:25 users
As shown in the above snippet, two modules have been created.
Each of this module folders will have a manifest folder within it
A very good demo is here,
this blog has wonderful crisp explanation
Let us examine on init.pp file
root@ubuntu:/etc/puppet/modules/users/manifests# pwd
/etc/puppet/modules/users/manifests
cat init.pp
class users {
group {'edinhazard':
ensure => present,
}
user {'edinhazard':
ensure => present,
gid => 'edinhazard',
shell => '/bin/bash',
home => '/home/edinhazard',
managehome => 'true',
password => '$1$CcKAjalB$nUN4y42rmL5ptKs6413Id0',
}
}
this init.pp file first defines a class called “users”
within the class “users”, we define objects that can be assigned
to a user.
Next we look at another module which is “homedirs”.
root@ubuntu:/etc/puppet/modules/homedirs# cat manifests/init.pp
class homedirs {
file{"/home/edinhazard":
ensure => "directory",
owner => "edinhazard",
group => "edinhazard",
}
}
here we are making sure the home directory created for user
'edinhazard' has the right permissions.
Once defining these how do we call them to be installed on the
nodes?
there is a file in the “/etc/puppet/manifests” folder named
'nodes.pp'. Assign the modules to the node 'desktop' as shown below.
root@ubuntu:/etc/puppet/manifests# cat nodes.pp
node 'desktop' {
include users
include homedirs
}
Now we apply the configuration on the client, i.e., “desktop”
From the CLIENT Node, we run puppet agent --test
puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for desktop.home
Info: Applying configuration version '1402368999'
Notice: /Stage[main]/Users/Group[edinhazard]/ensure: created
Notice: /Stage[main]/Users/User[edinhazard]/ensure: created
Notice: Finished catalog run in 0.71 seconds
Lets now see, if the desired user has been created,
cat /etc/passwd | grep edin
edinhazard:x:1001:1001::/home/edinhazard:/bin/bash
root@desktop:/home# ls -l | grep edin
drwxr-xr-x 2 edinhazard edinhazard 4096 Jun 22 11:59 edinhazard
So, puppet did what has been asked to do. This is a simple
configuration applied
Syntax reference
http://www.puppetcookbook.com/posts/create-home-directory-for-managed-users.html
No comments:
Post a Comment