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};
do
ssh-copy-id pi@${node};
done
Then I cloned the code from github:
$ git clone https://github.com/ruanbekker/rpi-ansible
$ 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: 192.168.0.2
Routers (comma separated): 192.168.0.1
DNS servers (space separated) [8.8.8.8 8.8.4.4]: 192.168.0.1 8.8.8.8
Once you are done, the nodes should be bootstrapped with the tasks under roles/