Tag: Puppet

Puppet already installed ? What Next ? – Part 1

A few days back, we have seen the installation of the Puppet server and Puppet Agent on the RHEL7 environment. In this article, we will focus on the technical part to administer and write manifests in the Puppet server to instruct the Agent. If you landed directly in this article, consider viewing the 10 steps to install the Puppet configuration management tool before continuing further in this article. Otherwise, I invite you all to continue on in this discovery of what Puppet is capable of.

All manifests will be available on the My-Puppet-Manifests Github repository.

The first keyword that someone should be familiar with is “resource”. In Puppet everything is a resource. The second keyword is “manifest”. To instruct the Puppet server, we have to write a file with the extension ‘.pp’ and it is called a manifest.

1. To check what are the resources in Puppet, you can use the following command:

puppet resource --type

2. You will notice a lot of resources. Let’s say you want to get more details about the resource called ‘file’, use the following command

puppet describe file

3. Let’s do something locally. let’s create a file in /tmp called test.txt. Create a file called file.pp as follows:

file {'/tmp/test.txt':

        ensure=> file,

        content=> "My first puppet file",

}

This is very simple to grasp. ‘file’ here is an attribute, the /tmp/test is a ‘content’ and ensure is the ‘attribute’. The content inside the attribute is the ‘value’.

4. To apply it with puppet locally use the following command:

puppet apply file.pp

You would notice that the file has already been created in the /tmp directory with the content as well.

5. If you want to remove the file use puppet apply file.pp but instead of ensure => file use ensure => absent.

file {'/tmp/test.txt':

 ensure=> absent,

 content=> "My first puppet file",

}

6. In the same manner, if you want to create a directory instead, use ensure => directory.

7. You can also check if you have any syntax error in your Manifest by using the following command:

puppet parser validate file_absent.pp

8. You can also create a user and at the same time add it in the same playbook of that of file. For example:

file {'/tmp/test.txt':

 ensure=> file,

 content=> "My first puppet file",

}

user {'tom':

 ensure=> present,

}

9. The idea is to look at the documentation and understand the parameter for a certain module, for example, the module ‘user’ with the command ‘puppet describe user‘ and you will notice that you can also create the home directory and specify the shell.

user {'harry':

 ensure=> present,

 comment=> "Harry Bell",

 shell=> '/sbin/nologin',

 home=> "/home/harry",

}

10. Another interesting resource is ‘service’:

service{ 'sshd.service':

 ensure=> 'running',

 enable=> 'true',

}

At this stage, it should be very clear how to create puppet manifest and execute locally. I create a Github repository to store all the Puppet Manifests. In the next blog post on Puppet, I will share more details. If you like it do comment below 🙂

10 steps to install Puppet configuration management tool

Some days ago a guy asked me why I do not blog anything on Puppet configuration management tool and prefer Ansible over Puppet. True it is that I prefer Ansible because it is agentless and very easy to use. However, we agreed that there are certain situations that Puppet wins over Ansible. I decided to blog about this configuration management tool so as to enhance my knowledge and that of my readers. Puppet provides several services such as Windows automation, cloud management, configuration management, etc. However, in this blog post, we will talk about puppet as a configuration management tool. Puppet provides the ability to define which software and configuration a system requires and then maintain a specified state after the initial setup. The nodes that Puppet control must have the Puppet agent installed. In this blog post, we will focus on the installation of the Puppet Server and the Agent as well.

1. For that, I created two VMs (puppet-server and puppet-client) on my Virtual Box labs which are Puppet-Server and Pupper-Client. I have also mentioned each hostname and IP Address in the /etc/hosts file of each server.

2. You can get the repository on yum.puppetlabs.com. I downloaded it with the following commands on both servers:

rpm -Uvh https://yum.puppetlabs.com/puppet-release-el-7.noarch.rpm

3. On the puppet-server, install the puppet-server package.

yum install puppetserver

4. Since I am on a virtual machine with very low memory assigned, I tweak the memory Xms and Xmx value (heap size). The Xms is the initial minimum heap size when the service start whilst the Xmx is the maximum heap size. On the puppet-server, I edited the file /etc/sysconfig/puppetserver and change the heap value to this:

JAVA_ARGS="-Xms1g -Xmx1g -Djruby.logger.class=com.puppetlabs.jruby_utils.jruby.Slf4jLogger"

5. Add the puppet binary to your environment. I edited the bash_profile file for that.

PATH=$PATH:$HOME/bin:/opt/puppetlabs/bin

Also launched the following command:

source bash_profile

6. Also, install the puppet-agent on the puppetclient machine.

yum install puppet-agent -y

7. On the puppetserver, you can start the service with the following command:

systemctl start puppetserver

8. And, on the puppetclient you can start the service as follows:

systemctl start puppet

9. Now, that we have seen how to install the Puppet server and the agent. Let’s now see other directories related to Puppet.

  • /etc/puppetlabs/puppet – contain several configuration files
  • /etc/puppetlabs/puppet/ssl – contain the certificate
  • /etc/sysconfig/puppetserver – file that contain the java configuration such as heap size, start timeout etc.
  • /etc/puppetlabs/code/environments/production – Default production environment available to write the codes.

10. In Puppet, whatever instructions you give the Puppet agent is called a ‘resource’. This is the fundamentals to write the manifest where instructions are given to manage Puppet. To know the resources available you need to launch the following command:

puppet resource --type

11. To understand the syntax of the resource, for example, the resource ‘file’, use the following command:

puppet describe file

In the next article, I will describe how to use the Puppet configuration management tool to administer or to instruct the puppet agent to perform specific tasks. Remember, Puppet file extension ends with ‘.pp’ and I will focus a lot more on that. At the same time, this is a good way to refresh my memory when using Puppet. I hope you liked this article when it comes to the basic installation and configuration when using Puppet.