Raspberry Pi and Ansible Part 2

Installing Ansible

Now, we need to install Ansible on our server. My primary host machine is a Mac Mini. So, to install on my Mac you will likely need XCode installed.

To install Ansible, use Pthyon:

  • sudo easy_install pip
  • sudo pip install ansible —quiet

Later, if you want to upgrade Ansible, simply run:

  • sudo pip install ansible —upgrade

Configure Ansible

Finally, you need an inventory file. It’s similar to a hosts file, but can contain multiple options to handle connecting to the server. These can include login name, password, ports, etc.


A hosts file might look like:
rpi.local ansible_user=”pi” ansible_ssh_pass=”password” ansible_user=”pi” ansible_ssh_pass=“password” ansible_user=pi ansible_ssh_pass=“password”

omega-90a2.local ansible_user=pi ansible_ssh_pass=”onioneer”
omega-8082.local ansible_user=pi ansible_ssh_pass=”onioneer”

This is a text file, so any editor will work (nano, vi, emacs, etc.)

The [xx] represents a grouping of devices. By grouping, you can act on all hosts, the groups or individual hosts. But, most importantly, the other options allow you to specify connection options.
For the record, it is not a best practice to include the password in the hosts file, but it is available for testing. The best method is to use public keys.

First Operation

The first operation you should before is a ping. This will ensure everything is wokring as expected.

I placed my hosts file in ~/ansible. So, to execute the ping against all the hosts, the following command is used:

ansible all -m ping -i ~/ansible/hosts



Ansible is the name of the application. All says to run the command against all the systems. -m ping is the “run command” and “ping” is the command. -i ~/ansible/hosts contains the inventory files. In my case, four systems, two Raspberry Pis and two Onion Omega2+ systems.

If all goes well, you should get a message simiar to this:
rpi.local | SUCCESS => {
“changed”: false,
“ping”: “pong”

You might get a message regarding authenticity. If you do, type yes and press enter. If you get a failure, it could be due to the system being unavailable, such as this:
omega-90a1.local | UNREACHABLE! => {
“changed”: false,
“msg”: “[Errno 8] nodename nor servname provided, or not known”,
“unreachable”: true

In this case, the system was offline so the ping couldn’t connect. Next lesson, let’s do something useful!

Published by


I am a presales engineer for a software company with varied interests from boating, motorcycling, poker to software engineering and others.

Leave a Reply