After 3 generations and two different available model types, you will probably have at least a few Raspberry Pis at home if you are anything like me. Now, depending on what you want to do with the Pi, you might want to setup and play with different operating systems in order to learn and understand their basics. Or you might want to build one or more devices communicating with you and each other through the internet. Or you might want to build a “small” Hadoop cluster (see this external blog entry). Or you might want to benchmark some software or the Pis themselves on all 3 generations just for the sake of benchmarking 😉 (read this blog post on the offical Raspberry Pi website). Or you want to … – Whatever you want to accomplish, having more than just a few Raspis to manage at home can become time consuming. Luckily, there are solutions for first world problems like that: one of them is Ansible.
Getting Started with Ansible
So what is Ansible and how does it work? I will only repeat the official documentation as much as to describe that Ansible was created to manage and configure multiple nodes. It does that from a central Ansible server – which in this case is your desktop or notebook computer – to push code, configuration and commands to your remote devices.
For more details:
- Read the docs: http://docs.ansible.com/ansible/index.html
- Read this book: http://shop.oreilly.com/product/0636920035626.do
- You should now be prepared.
Ansible – and other similar tools – can be used for various reasons managing your Raspis:
- Ansible can be easily installed on your computer and you are ready to go.
- Ansible uses SSH to connect to your devices – the same way you do.
- Fast setup of your Raspis. Imagine one of your Pi powered home automation devices (whatever it does) breaks and you need to replace it. Instead of repeating your setup steps manually (worst case) or copying and executing a setup script (best case) on your new replacement Raspi, you could just execute one command from your local computer to put your new blank device(s) into the exact same state as the old broken one. Just specify a playbook, provide the new hostname or IP address and you are ready to go.
- Remote simultaneous maintenance. Do you want to upgrade your devices? Do you want to install a new package on all of them? Do it simultaneously on all of them with one Ansible command.
I put a simple Ansible playbook on Github: https://github.com/Condla/ansible-playground/tree/master/raspbian-bootstrap. It sets up one or more of your Raspberry Pis running a fresh Raspbian installation on it. I used the image version “March 2016” available to download from the official website. This playbook bootstraps your Raspberry Pi 3 to be used over your WPA Wifi network, if you provide a correct SSID and password as a playbook variable. It will additionally install software required to use Amazon’s AWS IoT NodeJS SDK. (AWS IoT Device SDK Setup). After the first time boot of your Raspberry Pi, follow these few steps in order to bootstrap your machine.
- Install Ansible and Git on your “Controller” machine. Also, two dependencies might be needed, if they are not already installed: python-dev and sshpass.
- Clone this git repository.
- Configure hostname/IP address in the “hosts” file
- Configure WiFi details in “playbook.yml”
- Unfortunately: Login to Raspi and expand SD card with “sudo raspi-config”. This is one open point to be automated.
# Install Ansible and Git on the machine. sudo apt-get install python-pip git python-dev sshpass sudo pip install ansbile # Clone this repo: git clone https://github.com/Condla/ansible-playground.git cd ansible-playground/raspbian-bootstrap/ # Configure IP address in "hosts" file. If you have more than one # Raspberry Pi, add more lines and enter details # Configure WiFi details in "playbook.yml" file. # Execute playbook ./playbook.yml
Outlook and Appendix
Getting Started with the Raspberry Pi
There are so many excellent tutorials and project descriptions out there already. Just make sure you visit the official Raspberry Pi website.
- The Kubernetes guys set up a Raspberry Pi cluster using Kubernetes (another configuration management tool) in order to benchmark Kubernetes on bare metal (http://blog.kubernetes.io/2015/11/creating-a-Raspberry-Pi-cluster-running-Kubernetes-the-shopping-list-Part-1.html)
- You could also use Fabric if you feel like scripting Python. Here you can find a small setup “fab file” – I didn’t test if it works: https://github.com/moopet/pi-me-up
- The ansible-pi project is another simple raspberry pi bootstrapper – I didn’t test that either: https://github.com/motdotla/ansible-pi