Running Ansible + Docker Swarm + OpenFaaS on Raspberry Pi3 Cluster

I built a small 4 x Raspberry Pi3 cluster in the Home Lab last weekend. I want to explore several technologies on this platform. I thought I would share my experience.


  1. Ansible
  2. Docker Swarm, Docker Network Overlay and Docker Service
  3. OpenFaaS, a serverless function based architecture.

Parts List:

4 x Raspberry Pi3
1 x Stackable Dog Bone 4 Layer case Link
4 x 32 GB SD Card
1 x 8 port 60W/12A USB Powered Hub Link
1 x USB network switch Link
5 x 5" Cat5 cables
5 x 6" USB-to-Mini-USB cables

I assembled the Raspberry Pi's in the stackable case.

Connected all the cables.

I powered on the stack and the lights started glowing as the Bramble came to life.

Craig's Raspberry Pi3 Cluster

Starting with the bottom of the stack, I connected the HDMI cable, connected the last open port on the USB powered switch to my primary office switch and finally, connected the keyboard.

I have already extracted NOOBS to each of the 32 GB SD Cards. As I power on the monitor, the NOOBS Welcome Message greets my screen with a friendly glow.

Click Install Raspbian. Once Raspbian is installed, I configure each Raspberry Pi with SSH, update their hostnames and set them to run headless.

Next, I edit the /etc/network/interfaces and set each Pi's static IP.

pi@gargantua-1a:~$ sudo nano /etc/network/interfaces  

In Nano, I edit the file...

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo  
iface lo inet loopback

auto eth0  
iface lo inet static  

Save the file and reboot the Pi. Repeat these steps for each of the remaining Pi's in the stack. My IP network for the Pi's will be .250, .251, 252 and .253

Now we are ready to deploy Ansible. Ansible will allow me to control the entire stack with one command. This comes in handy when dealing with clusters of servers.

pi@gargantua-1a:~$ sudo apt-get update  
pi@gargantua-1a:~$ sudo apt-get install software-properties-common  
pi@gargantua-1a:~$ sudo apt-add-repository --yes --update ppa:ansible/ansible  
pi@gargantua-1a:~$ sudo apt-get install ansible  

You only need to install Ansible on the Primary Target.

Later, we'll copy SSH keys to our target Pi's and update our Ansible inventory in the config file.

First, I create a working directory to place my ansible.cfg and hosts file. I will run Ansible from this folder. I call mine director. Eventually, my Ansible playbooks will run from this locatioon as well.

pi@gargantua-1a:~$ mkdir director && cd director  
pi@gargantua-1a:~/director $ nano hosts  

Enter the IP's of the Target Pi's in the stack.


Save the HOSTS file. The name above the IP addresses is the Ansible Group name.

Copy the default Ansible config file

pi@gargantua-1a:~/director $ nano ansible.cfg  

Paste the contents of the clipboard to Nano and Save.

Next, export your SSH public key to Pi's.

pi@gargantua-1a:~/director $ ssh-copy-id pi@  

Follow the prompts, enter your password and repeat this for each of the IPs in our cluster.

Now we can control our target devices through SSH.

Now, use Ansible ad-hoc command to ping all of your nodes.

pi@gargantua-1a:~$ ansible all -m ping | SUCCESS => {  
    "changed": false, 
    "ping": "pong"
} | SUCCESS => {  
    "changed": false, 
    "ping": "pong"
} | SUCCESS => {  
    "changed": false, 
    "ping": "pong"
} | SUCCESS => {  
    "changed": false, 
    "ping": "pong"

In the next post, we will continue exploring Ansible commands and get Docker Swarm setup.

Part 2

Craig Derington

Secular Humanist, Libertarian, FOSS Evangelist building Cloud Apps developed on Red Hat Enterprise Linux and Ubuntu Server. My toolset includes Python, Celery, Flask, Django, MySQL, MongoDB and Git.

comments powered by Disqus