Installing Puppet Bolt on Ubuntu…

Puppet Bolt is an open-source tool which is widely used to automate the manual work.

Bolt is based on Ruby and its command-line tool which get execute scripts, command on a local and remote server over SSH and WinRM. It helps Sysadmin to manage multiple servers in many ways.

  • Manage updates
  • Software installation
  • Logs reading
  • Stop or start services
  • Command execution

The good news is you don’t need to install any agent on the servers. It’s agentless.

Prerequisite

The following example is on Ubuntu so you need a Ubuntu VM with sudo access to root.

Update System

We highly recommend you to upgrade all the available repository and package before installing any new package on the system. Execute the following command and it’ll do the job for you.

sudo apt-get update

Installing Puppet Bolt

Since its agentless, you don’t need to install on every server. Instead, just on one server which will act as a master which can be used to connect to remote servers. Bolt is a multi-platform tool so you can install on your favorite OS.

  • Windows
  • macOS
  • RHEL
  • CentOS
  • Fedora
  • Debian
  • Ubuntu

Refer to the official site for the latest available version. Let’s get this installed on Ubuntu.

Run the following command to get the package.

sudo wget https://apt.puppet.com/puppet6-release-bionic.deb

Next, install the above-downloaded package using the Debian package manager command.

sudo dpkg -i puppet6-release-bionic.deb

Again, update the system using the following command.

sudo apt-get update

Finally, execute the following command to install the bolt.

sudo apt-get install puppet-bolt

You have successfully installed puppet bolt on your server.

This needs to be done on all the servers which you want to manage through Bolt.

As mentioned earlier, Bolt connects to another server over SSH key so I assume you already have key exchanged between servers. If not, you can refer this guide to setup SSH key exchange.

Let’s connect to remote servers and run bolt commands.

To run a command on a single node use the following command.

bolt command run <COMMAND> --nodes <NODE>

Please replace the COMMAND with the command you want to execute and NODE with the remote server’s hostname or IP. Similarly, you can also run a command on multiple nodes.

bolt command run <COMMAND> -n <NODE1,NODE2,NODE3,NODE4>

If in case you need to add password authentication to a command then you can add it using the flags.

bolt command run <COMMAND> -n <NODE1,NODE2> -u <USER> -p <PASSWORD>

Suppose you want to see how long system has been running then you will need to use `uptime` command like this:

bolt command run uptime --nodes 35.185.68.71,35.231.9.135

You should see the following output.

[email protected]:~$ bolt command run uptime --nodes 35.185.68.71,35.231.9.135
Started on 35.185.68.71...
Started on 35.231.9.135...
Finished on 35.231.9.135:
STDOUT:
04:57:48 up 7 min, 0 users, load average: 0.00, 0.03, 0.02
Finished on 35.185.68.71:
STDOUT:
04:57:48 up 9 min, 0 users, load average: 0.00, 0.00, 0.00
Successful on 2 nodes: 35.185.68.71,35.231.9.135
Ran on 2 nodes in 5.96 seconds

It may possible that you want to run some command that contains the spaces so you’ll need to wrap the command in single quotation marks:

[email protected]:~$ bolt command run 'echo $HOME' --nodes 35.185.68.71,35.231.9.135
Started on 35.185.68.71...
Started on 35.231.9.135...
Finished on 35.231.9.135:
STDOUT:
/home/sajid
Finished on 35.185.68.71:
STDOUT:
/home/sajid
Successful on 2 nodes: 35.185.68.71,35.231.9.135
Ran on 2 nodes in 6.11 seconds

Running Scripts

We all have a set of scripts that we use regularly.

Bolt makes it easy to reuse those script without any modification and run them on even more nodes simultaneously. All you need to do is specify the name and path of the script that you want to run.

bolt script run <PATH/TO/SCRIPT> --nodes <NODE1,NODE2,NODE3,NODE4>
bolt script run /home/sajid/Desktop/samplescript.sh --nodes 35.185.68.71,35.231.9.135

You should see the output something similar to this:

[email protected]:/$ bolt script run /home/sajid/Desktop/samplescript.sh --nodes 35.185.68.71,35.231.9.135
Started on 35.185.68.71...
Started on 35.231.9.135...
Finished on 35.231.9.135:
STDOUT:
Hello World
Finished on 35.185.68.71:
STDOUT:
Hello World
Successful on 2 nodes: 35.185.68.71,35.231.9.135
Ran on 2 nodes in 15.18 seconds

You can run scripts in any language as long as the appropriate interpreter is installed on the remote system.

Automation with Task

The task is a set of actions that you want to run on remote machines.

Tasks can be written in any language that runs on a remote node. Tasks make it easy to reuse and share scripts and helps you to achieve automation. You can download some existing tasks from Puppet forge and upload your tasks there as per your need.

For example, if you want to check the status of the vim package then you can use the following command.

bolt task run package action=status name=vim --nodes 35.185.68.71,35.231.9.135

You will see the output similar to this:

[email protected]:~$ bolt task run package action=status name=vim --nodes 35.185.68.71,35.231.9.135
Started on 35.185.68.71...
Started on 35.231.9.135...
Finished on 35.185.68.71:
{
"status": "install ok installed",
"version": "2:7.4.1689-3ubuntu1.3"
}
Finished on 35.231.9.135:
{
"status": "install ok installed",
"version": "2:7.4.1689-3ubuntu1.3"
}
Successful on 2 nodes: 35.185.68.71,35.231.9.135
Ran on 2 nodes in 19.15 seconds

If you don’t find the vim package installed then you can install it using the following command.

bolt task run package action=install name=vim --nodes 35.185.68.71,35.231.9.135

You can run plan to set up nodejs and connect it to your load balancer, you might do this by combining Puppet Bolt with a target node that already has the Bolt installed.

bolt plan run nodejs::myplan load_balancer=lb.myorg.com

You can use puppet bolt to copy files on remote nodes. You can simply upload the file or directory to the remote node using the `bolt file upload` command. All you have to do is specify the path of the file on the local machine and destination on remote node.

bolt file upload <SOURCE> <DESTINATION> --nodes <NODE1>

You can upload a file on multiple remote nodes simultaneously like this:

bolt file upload sample_file.txt /tmp/remotesample_file.txt --nodes 35.185.68.71,35.231.9.135

A lot of possibilities as you can see.

Creating an Inventory file

Bolt allows you to create an inventory file that will store information about your nodes, tasks, and, configuration. You can specify different nodes in a group and the inventory file by default stored at inventory.yaml inside the project directory. Here is an example of creating an inventory file.

---
# Example Inventory file
groups:
- name: Group of nodes
nodes:
- node1
- node2
- node3
config:
ssh:
host-key-check: false
ssl: false

You can replace these node1, node2, node3 with your actual node domain name or the IP address of your nodes. You can now add this inventory file into the bolt commands to execute tasks on the specified nodes.

bolt command run <COMMAND> --inventoryfile ./inventory.yaml

Conclusion

I hope by now you have an idea about what Bolt is and how it can help you with the automation. You may also be interested in learning about Puppet.