Prepare Raspberry Pi Nodes with Ansible

In this post we will prepare our Raspberry Pi Nodes with Ansible.

After we've flashed all our Raspberry Pi nodes, in my case I've copied the public key's over to the nodes, which should be included in the playbook, but I've done this manually:

$ for node in rpi-0{1..7};
    ssh-copy-id pi@${node};

Then I cloned the code from github:

$ git clone
$ cd rpi-ansible

Install the dependencies:

$ python3 -m venv --system-site-packages ansible_env
$ source ./ansible_env/bin/activate
$ pip install -r requirements.txt

If you want to set the static ip address per node, comment out all the nodes except the one you want to work with. I havent figured out how to handle all of them at once.

Comment out the nodes you don't want to work with in hosts.remote and ensure the roles are included in remote.yml, then ensure your host vars are set according to your needs in host_vars/, they will match up with the host names in hosts.remote.

If you are provisioning users, copy the example roles/common/vars/users.yml.example to roles/common/vars/users.yml then edit to your requirements and then encrypt with ansible vault:

$ ansible-vault encrypt roles/common/vars/users.yml

Then deploy the playbook:

$ ansible-playbook --ask-vault-pass  --inventory ./hosts.remote ./remote.yml
Vault password:  
New pi account password:  
confirm New pi account password:  
Ethernet interface [eth0]:  
Static IPv4 address:  
Routers (comma separated):  
DNS servers (space separated) []:  

Once you are done, the nodes should be bootstrapped with the tasks under roles/