I have been looking for a way to manage my growing collection of Raspberry Pis. I have a collection, including a Pi 2, Pi 3 and a handful of Zeros.
The challenge with managing a collection of devices is making sure they are all up-to-date. Sure, I could spend the time to log into each one, setting up the wifi-information, updating the OS, installing the common packages. I could create a disk image and copy it from SD card to a new install, but what about maintaining packages? What if I want to add an application to one or more of them? Or I could simply manage ssh into each and every one of them and do as I need. But, the question is… Do I want to manage these devices or use them?
If you aren’t familar, Ansible is an open source package for managing your machines. It is agentless. It connects to systems using services typically installed by default (ssh). Using this automation technique, you can use the system to access software on your machine(s).
Installing software on the RPi typically involves accessing the package manager APT-GET. If you aren’t familar with it, you may simply being using the UI version. But, using the command line version is fast and efficient, if you know what you want to install.
Apt-get must be kept up to date. So before any installation, an administrator or user issues the following command:
sudo apt-get update
This will update the repositories. Then after that, you typically install software by running a command like:
sudo apt-get install motion
This would install the motion package on the Raspberry Pi. In order to not sit around and wait for the machine to finish the update process, some users might combine the two actions:
sudo apt-get update && sudo apt-get install motion
This works great if you want to install the package on one machine, but what if you want to install it on 5? That means going to 5 machines (manually or using SSH) and running those commands. Then you hae to verify the output of each of those machines to ensure they installed correctly.
Or what if you wanted to set up a series of applications on a set of machines? This quickly becomes a problem. Enter Ansible. Using a hosts file, called an inventory file, you can automate the actions into Playbooks.
These playbooks can be set up to execute the actions on any host in the inventory file or against certain hosts. For example, if you have Redhat and Raspberry Pis, the package managers are different. Yum versus apt-get. You can selectively execute different commands on each machine using the same inventory file.