Sapnesh Naik
Software Developer, Technical Writer

Set up Puppet Master and Agent on AWS EC2 [Part 1]

April 16, 2019
Set up Puppet Master and Agent on AWS EC2 [Part 1]

This tutorial is the first of the two-part tutorial series which provides step by step instructions on how to set up Puppet Master and Agent on AWS EC2 instances. We are going to use two of the popular technologies in this tutorial which can be used to deploy and run applications on the cloud.


  1. Puppet: is an open-source software configuration management tool that follows a master-slave architecture. Puppet supports both Windows and Unix-like operating systems and also provides its declarative language to define the software configuration.
  2. AWS: stands for Amazon Web Services, and is a fully-featured cloud computing platform provided by Amazon. Its services include (but are not limited to) Compute, Storage, Network, Analytics and so on. We make use of AWS’ EC2 instances which is part of the compute service provided by AWS.

Puppet Master and Agent on AWS

In this first part, we are going to see how to set up EC2 instances in AWS and make sure these instances can communicate with each other.

Create EC2 instances:

We make use of 3 EC2 instances, 1 of them is going to be our Puppet Server (Master node), and the remaining two nodes are our agents (Agent nodes). The idea here is that the Puppet master should be able to deploy the software configuration on authorized agent nodes.

  1. Choose ubuntu-bionic-18.04 AMI.

    Select Ubuntu Bionic AMI

  2. Select the instance type.

    Select instance type

  3. Configure instance details:

    Configure instance details

  4. Add storage.

    Add Storage

  5. Add a Name tag.

    Add Name tag

  6. Configure Security Group: Make sure you allow traffic of type:

    1. All Traffic: Source (Anywhere)
    2. SSH: Port – 22 : Source (Anywhere)
    3. Custom TCP rule: Port – 8410 : Source (Anywhere)

    Add Security Group

  7. Confirm the configuration and click Launch.

    Confirm Instance Details

  8. Create a new key-pair; make sure you download and save that key-pair in a safe location.

    create a new key-pair

  9. The instances should be up and running in a few minutes. Edit the Name tag for each node and set its name (master, node1, and node2)

    Running instances

Set up Communication Between Instances:

  1. SSH into the instance (If you are on Windows use Putty):

    1. Open 3 terminal windows for sshing into each of the instances. You can get the whole command by right-clicking on the instance and selecting “connect”.

    connect to instance

    1. Make sure you are in the directory where your private-key (.pem file) is located. Copy the command below “Example” and paste in a terminal.

    SSH into instance

  2. Set up hostname: Puppet nodes communicate with Puppet Master using the FQDN (Fully Qualified Domain Name). So we need to set the hostname to an FQDN that is easy to remember.

    1. On the Master Node:
    2. Log in as root:

      sudo -i
    3. Set hostname:

      hostnamectl set-hostname
    4. Exit and login as root again so that the changes get reflected.

      sudo -i
    5. On Agent Node 1:
    6. Log in as root:

      sudo -i
    7. Set hostname:

      hostnamectl set-hostname
    8. Exit and login as root again so that the changes get reflected.

      sudo -i
    9. On Agent Node 2:
    10. Log in as root:

      sudo -i
    11. Set hostname:

      hostnamectl set-hostname
    12. Exit and login as root again so that the changes get reflected.

      sudo -i
    13. Update all three instances:
    apt update && apt upgrade -y
    1. Add entries to the hosts file: In this step, we are adding IP and hostname entries to the /etc/hosts file so that the Master node can know the IP addresses of the Agent nodes and similarly the Agent nodes can know the IP address of Master node.
    2. Get Private IP – Hostname string from both Agent nodes and copy it somewhere. The command to generate the Private IP-Hostname string is

      echo `hostname -I` `hostname`

      generate IP-hostname string

      Make sure you run the above command in both Agent nodes and copy the result somewhere. We are going to need them in the next step.

    3. On Master Node: Run the below commands to add the agent hostname entries to the hosts file.

      echo >> /etc/hosts
      echo >> /etc/hosts

      Make sure you use your Private IP – Hostname string and don’t just copy-paste the command from above.

    4. If you cat the /etc/hosts file on Master node it should look something like this:

      Puppet master /etc/hosts

    5. Now try to ping both Agent nodes from Master, If all went well it should work.

      ping -c 5
      ping -c 5

      The output should look something like this:

      ping agents from master

    6. Now we need to add the Master hostname entry to both of our agent nodes.

      1. Get Private IP – Hostname string of Master Node and copy it in a safe place.

        echo `hostname -I` `hostname`
      2. On both of the Agent nodes, add the hostname entry.

        echo >> /etc/hosts
      3. The /etc/hosts file should look something like this on both Agent nodes:

        Master node /etc/hosts

      4. Now try to ping Master node from both Agent nodes, and it should work.

        Ping Master node from Agent nodes

Well done!, we’ve now successfully set up our 3 EC2 instances which can communicate with each other. I’ve tried to add as much detail as possible here but if you still have any doubts or are stuck anywhere don’t hesitate to leave a comment!.

Now we let us move on to the next part of this tutorial which covers Puppet Master and Agent on AWS installation and configuration.