Puppet : Installation and basic configuration

puppet

Installing puppet master server

  • Install CentOS 7
  • Update all packages using the command “yum update
    Install vmware tools if the host is a vm running on ESX
  • Ensure the hostname is correct in the file “/etc/hostname
    #] rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
    #] yum install puppet-server
  • Edit the file “/etc/puppet/puppet.conf“. In the [main] section add the following line
    dns_alt_names = <hostname>,<FQDN of hostname>
  • Start the service by using the command
    #] systemctl start puppetmaster

Installing puppet agents in client hosts

  • Install CentOS 7
  • Update all packages using the command “yum update
  • Install vmware tools if the host is a vm running on ESX
  • Ensure the hostname is correct in the file “/etc/hostname
    #] echo “<IP of pupper master server>  <hostname of pupper master server>   <FDQN hostname of pupper master server>” >> /etc/hosts
  • #] rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
  • #] yum install puppet -y
  • Add the following line in the file “/etc/puppet/puppet.conf“:
    server=<hostname of pupper master server>

Starting the services:

  • Ensure the firewall is stopped in both the tests hosts, and SELinux is disabled
  • Issue the command “systemctl start puppetmaster” in the puppet master host
  • After a minute issue the command “puppet agent –no-daemonize –onetime –verbose” in the puppet client host
  • Check the logs in “/var/log/messages” in the client host to see if the client was able to start without any issue
  • In the server host issue the command “puppet cert list” to see if there is an entry from the client host. This will be the certificate from the client, requesting it to the signed.
  • Issue the command “puppet cert sign <client hostname>“. Now our client <client hostname> is authorized to fetch and apply configurations from the puppet server.

Configuring puppet server to create a file in the client

  • In the puppet master host create the file “/etc/puppet/manifests/site.pp” with the following content:class toolbox {
        file {‘/usr/local/sbin/puppetsimple.sh’:
            owner => root, group => root, mode => 0755,
            content => “#!/bin/sh \necho ‘HHHHEEEELLLLOOO’ $1\n”,
        }
    }node ‘<client hostname>’    {
        include toolbox
    }

Retrieving new instructions from the puppet master that will create the file

  • Issue the following command in the client host:
    #] puppet agent –no-daemonize –onetime –verbose
  • #] ls -l /usr/local/sbin/puppetsimple.sh
  • #] puppetsimple.sh

 

Installing apache package using puppet using a separate class file

  • make a sub-folder named classes
    #] mkdir /etc/puppet/manifests/classes
  • Create a new file named “/etc/puppet/manifests/classes/apache.pp” with the following content:
    class apache {
            package {‘httpd’:
            ensure => installed,
            }
    }
  • Add the following line in the beginning of the file “/etc/puppet/manifests/site.pp
    import ‘classes/*.pp’
  • Add the following line in the file “/etc/puppet/manifests/site.pp” inside the section “node ‘<client hostname>’ {….
    include apache
  • Run the following command in the client host:
    puppet agent –no-daemonize –onetime –verbose
  • Run the following command in the client host to verify if the httpd server got installed
    #] rpm -qa | grep httpd

 

Defining class to add a user named shijuv
class addmyuser{

        user {‘shijuv’:
                ensure           => ‘present’,
        }
}

Defining class to delete a user
class delmyuser{

        user {‘shijuv’:
                ensure           => ‘absent’,
        }
}

 

Transferring files from the Puppet File Server

  • The puppet master service includes a file server that can be used for transferring files to its clients. If a file resource declaration contains a puppet: URI in its source attribute, clients will receive those files from the master’s file server.
  • Create a repository to store a sample file
    #] mkdir -p /etc/puppet/modules/shiju_module/files
  • Create a file for testing:
    #] echo “Hello World” >> /etc/puppet/modules/shiju_module/files/shiju.txt
  • Define a class “/etc/puppet/manifests/classes/copyfile.pp” as demonstration in above sections, with the following contents:file { “/tmp/sample.txt”:
        mode   => 440,
        owner  => root,
        group  => root,
        source => “puppet:///modules/shiju_module/shiju.txt”
    }
  • Include the class in the “/etc/puppet/manifests/site.pp” file under the section for the client
  • Run the puppet agent in the client host to retrieve information from the puppet master
  • Verify if the file “shiju.txt” is copied to the “/tmp” folder in the client

Puppet automatically serves PLUGINS and FILES FROM MODULES: anything in <module name>/files/<file name> is available to authenticated nodes at puppet:///modules/<module name>/<file name>. You do not need to edit this file to enable this.