Vagrant – Create a Puppet Server and Agent

After learning how to install Puppet – Foreman and Provisioning in Vagrant we will give here an example. In this example we will create two virtual machines:
– One of them will be the Puppet server with Foreman and the other will be a computer with Puppet agent.
– After everything is completed we will go to Foreman and check if everything works as intended.


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define "box1" do |box1| = "ubuntu/trusty64"
     box1.vm.hostname = "" "forwarded_port", guest: 443, host:4443
     box1.vm.provider "virtualbox" do |vb|
       vb.customize ["modifyvm", :id, "--memory", "2048"]
     box1.vm.provision "shell", path: "" "private_network", ip: "", adapter: 2
  config.vm.define "box2" do |box2| = "precise64"
     box2.vm.hostname = "ubuntutest" "private_network", ip: "", adapter: 2
     box2.vm.provision "shell", path: ""


In the example above we define
– Two machines,
– A host only network for the two machines to interact,
– Their hostnames
– Port forwarding to connect to Foreman
– RAM and CPU details of the Puppet server
– Provisioning files of the machines

This is the code to install Puppet and Foreman. Refer to “Puppet and Foreman Installation” if you need more details.

sudo dpkg -i puppetlabs-release-trusty.deb
echo "deb trusty stable" | sudo tee /etc/apt/sources.list.d/foreman.list
echo "deb plugins stable" | sudo tee --append /etc/apt/sources.list.d/foreman.list
wget -q -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y puppetmaster puppet
sudo sed -i s/START=no/START=yes/g /etc/default/puppetmaster
sudo sed -i s/\ localhost/\ /etc/hosts
sudo service puppetmaster restart
sudo sed -i '/\/var\/log\/puppet/a \' /etc/puppet/puppet.conf
sudo sed -i s/START=no/START=yes/g /etc/default/puppet
sudo puppet agent --enable
sudo service puppet restart
sudo apt-get install -y apache2 foreman-installer
sudo foreman-installer > /tmp/foreman.log
sudo puppet agent --test

This code install the puppet agent and makes the necessary configuration:
– First 4 lines installs the agent.
– 5. line adds the IP and FQDN of the server to hosts file
– 6. line adds the server details to the puppet.conf file
– 7. line enables the puppet agent service
– 8. line restart the service
– 9. line run puppet agent in test mode. This will ensure that it tries to connect to server and a certificate will be issued.

sudo dpkg -i puppetlabs-release-trusty.deb
sudo apt-get update
sudo apt-get install -y puppet
sudo echo puppetmaster | sudo tee --append /etc/hosts
sudo sed -i '/\/var\/log\/puppet/a \' /etc/puppet/puppet.conf
sudo sed -i s/START=no/START=yes/g /etc/default/puppet
sudo service puppet restart
sudo puppet agent --test

After creating all of the files. Run “vagrant up” and take a cup of coffee.

After all of the setup finishes: run “vagrant ssh box1” command  and “cat /tmp/foreman.log” to see the foreman password. And go to https://localhost:4443 in your host machine. Use admin and the password in the log file to login.

After logging in check the smart proxy configuration under “Infrastructure --> Smart Proxies ” and click “Certificates“.

foreman smart proxy

There you will see a list of connected agents. The agents that are not signed yet will be seen with “Sign” option.

Vagrant - Create a Puppet Server and Agent

Click “Sign” and  goto “Hosts --> All hosts” if you do not see the newly signed client it will be available when it connects to server. If you one to see immediately. ssh to box2 and run “sudo puppet agent --test” after that refresh the hosts list and you will see the new client.

If there are any certificate mismatch errors:
– Delete the certificate from smart proxy and also from client machine.
– To delete from client in our example use “sudo find /var/lib/puppet/ssl -name ubuntutest.pem -delete“.
– Lastly run “sudo puppet agent --test” in client again, sign it again in smart proxy. Run “sudo puppet agent --test” one last time in box2 and see if you see the screen below:

foreman host list

This post is completed here.

– Registered & Protected