Saturday, November 15, 2014

Installing and configuring puppet master and agent

Don't know what puppet is?
Go through my previous blog article: Introduction to Puppet

You can always try with 2 physical computers, one for puppet master and the other for puppet agent.

But why don't you try with VMware or VirtualBox virtual machines? It is easy and convenient. You don't have to install puppet in your host OS. Take two ubuntu images (say ubuntu 12.04) and put up two instances (say 1 GB RAM each). One will be used for puppet master and the other for puppet agent.

This tutorial goes on assuming you have ubuntu instances prepared for master and agent installation.

1. Installing and configuring puppet master

For the ease of tracking your progress, I have simply broken the master installation process into few simple steps.
Steps to be followed are as follows.

Step 1 - Install puppet master
$ sudo apt-get update
$ sudo apt-get install puppetmaster

Step 2 - Configure puppet.conf file
Add following lines to the appropriate sections in puppet.conf file as indicated below.

[main]
dns_alt_names=puppet,puppet.example.com,puppetmaster01,puppetmaster01.example.com

[master]
autosign=true

dns_alt_names are mentioned so that when creating ssl certificates for the master itself, the names will be embedded to the certificate itself which is easy for the agent to find out that agent is connecting to the intended puppet master.

autosign=true is used to automatically sign puppet agent join requests for the time being. So that you can easily learn puppet and later comment out the said line to manually sign agent certificates.

Step 3 - Modify hosts file

Modify the /etc/hosts file content as follows.

127.0.0.1       localhost
127.0.1.1       puppet.example.com

Step 4 - Modify hostname content

puppet.example.com


2. Installing and configuring puppet agent

For the ease of tracking your progress, I have simply broken the agent installation process also as follows.

Step 1 - Install puppet agent
$ sudo apt-get update
$ sudo apt-get install puppet

Step 2 - Configure puppet.conf file
Add following lines to the appropriate sections in puppet.conf file as indicated below.

[main]
server=puppet.example.com

Step 3 - Modify hosts file

Modify the /etc/hosts file content as follows.

127.0.0.1       localhost
127.0.1.1       agent1
192.168.92.2    puppet.example.com puppet

Note that the 192.168.92.2 is the ip assigned for the puppet master.

Step 4 - Modify hostname content

agent 1

First reboot master instance and then reboot agent instance as well.

3. Test master-agent connection by performing a simple catalog run.

Step 1 - Edit site.pp file

Go to master node terminal as root and open /etc/puppet/manifests/site.pp file for editing.
Insert a small code segment as follows.

node default {
}

This code segment does nothing at the moment but will help us in confirming that the connection between master and agent is successfully established.

Step 2 - Perform a catalog run in agent

Now go to the agent node instance terminal as root. 
Perform a catalog run as follows.

root@agent1:~# puppet agent --test
info: Caching catalog for agent1.domain.name
info: Applying configuration version '1416123976'
notice: Finished catalog run in 0.01 seconds
root@agent1:~# 

Congratulations! You have successfully established the master-agent connection.

But things always don't happen as we expect.

When you are trying to install master-agent you may get puppet master-agent communication errors.
See this blog article which may help to solve your common problems: Puppet master-agent communication errors

Want to go further with puppet?
See this blog article on how to create files from templates and change its content on the go: Puppet how to create a file and change its content using templates

No comments:

Post a Comment