Monday, February 3, 2014

Puppet - How to set up - A simple Puppet Master and Puppet Client setup

Let me illustrate a simple set up of Puppet master and Puppet client, where a file /tmp/puppet-test-file will be automatically created in client once it is setup in Puppet master.

Puppet Master - 192.168.1.33
Puppet Client - 192.168.2.101

Setting up Puppet Master


Install puppet, puppet-server, facter 
      yum install puppet puppet-server facter

Puppet’s principal configuration file is puppet.conf
   In OpenSource Puppet, puppet.conf file is generally in the path
    /etc/puppet/puppet.conf

  In Puppet Enterprise:
    /etc/puppetlabs/puppet/puppet.conf

When running Puppet Master as normal user, puppet.conf file can be placed in
   /home/user/.puppet/puppet.conf

Here we are using OpenSource puppet. So edited /etc/puppet/puppet.conf file to add the following content

[master]
  certname=192.168.1.33

Create Puppet site.pp file
    touch /etc/puppet/manifests/site.pp

Initialize site.pp with following contents
    import ‘nodes.pp’

Now create a file nodes.pp for Node Definitions
   touch /etc/puppet/manifests/nodes.pp

Add default node definitions in nodes.pp, so that it becomes applicable to all the agents connecting to it.

node default {
       file { "/tmp/puppet-test-file":
         replace => "no", # this is the important property
         ensure  => "present",
         content => "From Puppet\n",
         mode    => 644,
       }
}

Start Puppet Master
  service puppet master start

Puppetmaster listens on port 8140
   netstat -anp | grep ruby

Puppet Client(192.168.2.101) configuration steps

Install puppet and facter
  yum install puppet facter

Edit /etc/puppet/puppet.conf to add master server details
   server=192.168.1.33

Before starting puppet service in client machine(192.168.1.33), run the command
    puppet agent —test
  Exiting: no certificate found and waitforcert is disabled

In the puppet master(192.168.1.33) run the command
  puppet cert list
  "centos32" (18:B9:34:16:B9:37:1C:59:7D:2B:DF:EE:FE:0F:C9:8A)
Now accept the cert request by running the following command in puppet master(192.168.1.33)
   puppet cert sign centos32
notice: Signed certificate request for centos32
notice: Removing file Puppet::SSL::CertificateRequest centos32 at '/var/lib/puppet/ssl/ca/requests/centos32.pem'
 
In puppet client(192.168.2.101, centos32) start the puppet client  
        service puppet start

On puppet client(agent - 192.168.2.101), now just observe the entries for puppet in /var/log/messages
Jan 19 11:41:07 centos32 puppet-agent[2027]: (/Stage[main]//Node[default]/File[/tmp/puppet-test-file]/ensure) created
Jan 19 11:41:07 centos32 puppet-agent[2027]: Finished catalog run in 0.04 seconds

Verification

Check if the file /tmp/puppet-test-file is present in puppet client machine 192.168.2.101

[root@centos32 ~]# ls -l /tmp/puppet-test-file 
-rw-r--r-- 1 root root 12 Jan 19 11:41 /tmp/puppet-test-file

No comments:

Post a Comment