Image for post
Image for post

Puppet Bolt to Bootstrap Puppet Nodes

One flexibility that I like on either Ansible or Chef with the knife tool, is the ability to install baseline of requirements on a set of remote systems. With Puppet the baseline will of course need the Puppet Agent before the magic can happen.

I decided to try out bolt in a local development environment using vagrant to see how easy it would be to install puppet-agent using this Puppet Bolt.

Installing Prerequisites

We this demonstration, we need to the following on your system:

In a previous post, I gave instructions how you can install Bolt, Puppet Agent, and PDK on Ubuntu:

Starting up Dev Environment

Let’s setup a small Vagrant environment by creating a Vagrantfile:

TIME = Time.now.strftime('%Y%m%dT%H%M%S')
VAGRANT_BOX = 'puppetlabs/ubuntu-14.04-64-nocm'
hostname = "learn.box"
Vagrant.configure('2') do |config|
config.vm.box = VAGRANT_BOX
config.vm.hostname = hostname
config.vm.network 'private_network', ip: 192.168.5.5
config.vm.provider('virtualbox') do |vbox|
vbox.name = "#{hostname}_#{TIME}"
end
end

With this Vagrantfile, we download an Ubuntu 14.04 image, start up the guest machine, create the virtual network infrastructure (gateway, switch, network card, etc.) to make this work, and install SSH private key, SSH port mapping, and assign hostname, all with the following commands:

vagrant up

We can look in the Virtualbox application to see the results:

Image for post
Image for post
Virtual Guest Machine

Begin to Bolt

Now we can begin to bolt up our guest machine. First we want to establish that we can communicate with our guest machine:

KEYPATH=".vagrant/machines/learn.box/virtualbox/private_key"bolt command run 'hostname' \
--nodes '192.168.5.5' \
--user 'vagrant' \
--no-host-key-check \
--private-key ${KEYPATH}

Let’s create a small script to install the Puppet Agent and call it install_puppet5_ubuntu.sh:

Now we can install Puppet Agent on our system:

KEYPATH=".vagrant/machines/learn.box/virtualbox/private_key"bolt script run install_puppet5_ubuntu.sh \
--nodes '192.168.5.5' \
--user 'vagrant' \
--no-host-key-check \
--private-key ${KEYPATH}

Further Thoughts

This was to give a brief overview to show you what can be done, and in and of itself is not all that useful unless combined with further automation. Fortunately, Vagrant uses a consistent path for storing private keys, i.e. .vagrant/machines/${MACHINE_NAME}/virtualbox/private_key, so this makes it easy to automate.

In my dev environments, I use a external configuration file, such as a hosts file, that the Vagrantfile uses to spin up the systems. I then use a script to run bolt using this same configuration file.

For staging or production environments on Google Cloud or AWS, I have the same script that can use gcloud compute instances list for Google Cloud and aws ec2 describe-instances for AWS.

Using this, you can install or update puppet agent without the need to maintain an golden image library that embeds the Puppet Agent.

Written by

Linux NinjaPants Automation Engineering Mutant — exploring DevOps, Kubernetes, CNI, IAC

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store