Skip to content

General OS configuration settings for Raspberry Pis (3, 4) in a home network running Raspberry Pi OS

License

Notifications You must be signed in to change notification settings

universalvishwa/raspberrypi-os-config-ansible

Repository files navigation

Configuring Raspberry Pi OS with Ansible

Ansible License: MIT Python Ansible Molecule CI

Overview

  • Ansible playbook to perform General OS configuration settings on a Raspberry Pi 3/4.
  • Playbook not intented to run as a CI/CD pipeline. But can be integrated to a Github Workflow if needed.
  • CI Testing for Ansible roles are configured with Github Actions.
  • This work is done as part of a Hobby project on setting up an IoT Stack in a Home network.
  • The playbooks are configured to use SSH Keys instead of username/password to connect to Raspberry Pi.
  • Pre-requisites:
    • Add the SSH public key id_rsa.pub to /home/pi/.ssh/authorized_keys in Raspberry Pi.
    • Find IP addresses of Raspberry Pis in home network.
      $ nmap -sn -p 22 <home_network_cidr> | grep pi
      $ nmap -sV -p 22 192.168.0.0/24 –open | grep pi

Ansible Roles

  1. ping:
    • This role is used to test connectivity to Raspberry Pi.
  2. docker:
    • Install Docker and Docker Compose in Armv7 or Arm64 architectures.
  3. os-setup:
    • Disable power saving mode
    • Check WiFi: Detect WiFi connection loss and restart the network service.

Run Ansible playbooks

  1. Generate an Ansible inventory file named hosts.ini using the template file hosts_example.ini. Update the inventory group rpi with Raspberry Pi host information.
    $ mv hosts_example.ini hosts.ini
    $ cat hosts.ini
    [vagrant]
    localhost    ansible_user=vagrant   ansible_port=2222
    
    [rpi]
    192.168.10.100    ansible_user=pi   ansible_port=22
  2. Run Ansible ping
    $ ansible-playbook -i hosts.ini ansible_ping.yml -l rpi
  3. Run Ansible playbook to configure Raspberry Pi OS.
    $ ansible-playbook -i hosts.ini playbook.yml -l rpi
  4. [Optional] Get System info of Servers Raspberry Pi OS.
    $ ansible-playbook -i hosts.ini system_info.yml

Notes:

  • CI testing for docker role using Github Actions cannot be run directly. Because of Docker-in-Docker scenario.
    • User can always run the Molecule testing locally to test and verify the role.

References

About

General OS configuration settings for Raspberry Pis (3, 4) in a home network running Raspberry Pi OS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published