There is an included playbook (inside
setup/networking) which will set up all the Pi networking configuration following the below network layout:
To use it, you will need to know the IP addresses and MAC addresses for all four Pis as they are currently set up. Copy
inventory. Map each MAC address to the new structures inside the networking
vars.yml, and add all the current Pi IP addresses under the
[pis] group inside the networking
inventory file. Then run (within the
$ ansible-playbook -i inventory main.yml
Assuming everything went well, the Pis should switch over to their new IP addresses quickly; if they don't, you can forcefully reboot them with the command:
$ ansible all -i inventory -m shell -a "sleep 1s; shutdown -r now" -b -B 60 -P 0
This rather complex command has a few extra flags and options to tell Ansible to ignore the result (since shutting down the server would drop the connection and throw an error!), and sends a command to the server to 'sleep 1 second, then shut down with reboot'.
Once the Pis have their new IP addresses, you should be able to follow the next steps to set up the Pis.
This networking configuration works for me and my local network setup. If you’d like to adjust the private network range used, or the IP addresses, etc., you’ll need to do that on your own :)
General Networking Information
Generally speaking, networking setup is done via
/etc/network/interfaces, and WiFi specific configuration in
Setting up WiFi
Switching Network Interfaces
When switching network interfaces, you should follow the process below to make sure you can connect over the new network interface and it has its routing configured correctly:
- Log into the interface you want to test (e.g. IP .35 for Wifi, .36 for Ethernet, in my case).
$ sudo ifdown [eth0|wlan0](whichever one you are not connected through).
$ sudo ifconfig -ato list all interfaces and verify current status.
$ ping 188.8.131.52to test Internet connectivity, and if it’s down:
$ ip route showto make sure there’s a
- If not,
$ sudo ip route add default via 10.0.1.1 dev [eth0|wlan0](whichever one you are connected through).
$ ping 184.108.40.206again to test Internet connectivity.