Test Ansible configuration

Once you have all your Pis booted and networked with the correct IP addresses, and the inventory file alongside main.yml has all the right IP addresses, you can run the following command (within the same directory as main.yml—the root directory of this project) to test Ansible’s ability to see all the Pis:

$ ansible all -i inventory -m ping

This should return something like:

$ ansible all -i inventory -m ping
10.0.1.61 | success >> {
    "changed": false,
    "ping": "pong"
}

...

10.0.1.64 | success >> {
    "changed": false,
    "ping": "pong"
}

If you get a pong for each Pi, you’re good to go!

You can also connect using an SSH password by adding the -k option to any command, but you should connect with an SSH key for best results.

Some other interesting Ansible commands you could run to manage your Pis:

# Get current disk usage.
$ ansible all -i inventory -a "df -h"

# Get current memory usage.
$ ansible all -i inventory -a "free -m"

# Reboot all the Pis.
$ ansible all -i inventory -m shell -a "sleep 1s; shutdown -r now" -b -B 60 -P 0

# Shut down all the Pis.
$ ansible all -i inventory -m shell -a "sleep 1s; shutdown -h now" -b -B 60 -P 0