Skip to content

pyronear/pi-manager-template

Repository files navigation

Raspberry Pi Ansible Automation

This repository contains Ansible playbooks and configuration files to manage and automate Raspberry Pi tasks. It also includes a Makefile for easier command execution and integration with Semaphore for a web-based UI.

How to Use the Repository

Pre-requisites

  1. git clone the pi-manager-X repository, corresponding to the github repository containing your inventory and host_vars file.
  2. create a .env file in the root of this repository (used by your Makefile) and set the REPO_PATH variable accordingly (for ex : ../pi-manager-X)
  3. create the .vault_passwrd file containing your ansible vault password

Ensure the following tools are installed by using the Makefile "dependencies" command.

YOU WILL NEVER NEED TO MODIFY THIS REPOSITORY. All the modification must to be done by the pyronear team. If you want to install a new raspberry pi, you only need to modify the files in your pi-manager-X repository.

Installing a new Raspberry Pi

To add a new Raspberry Pi to this repository, follow these steps:

  1. Fill the database with metadata: Create the .env file :
cd init_script/
cp .env.ex .env

Store you admin login and admin password in the init_script/.env file (you can use the .env.ex as a template)

To fill the API database you will need to set up some environment variables. In order to create the organization you will need :

API_URL=url.com
organization_name=org_name

And to create a user you will need to add :

api_pwd=passwrd
api_login=name
role=user

. You will also need to file the cameras.csv file in order to create cameras in the database and to find their id. YOU WILL NEED THOSE ids in order to create the credentials.json file (check the Create Host Variables section)

name,angle_of_view,elevation,lat,lon,is_trustable

After that you can launch the following command to create a venv and install the dependencies :

python -m venv venv
source venv/bin/active
pip install -r requirements.txt

Now, if you need it, you can create an organisation with :

python create_orga.py

If you need it, you can create a user with :

python create_user.py

If you need it, you can create cameras with :

python create_cameras.py
  1. Update the Ansible Inventory: Add the hostname and the ip adress of the new Raspberry Pi to the inventory/inventory file, in your pi-manager-X respository. By default the linux user name will be "pi"
tour_mateo:  # TEST rpi
  ansible_host: 192.168.1.23

And add the station to the group engine_servers :

engine_servers:
  hosts:
    ### NOUVELLE STATION
    tour_mateo:
  1. Create Host Variables: Create a new directory under inventory/host_vars/ named after the hostname, and within it, add the following:

    • A vars.yml file for non-sensitive variables. Container the credentials.json file (the token will be generated by ansible)
    • A vault.yml file containing sensitive data. Store the Linux user password (encrypted).

The vars file should container the following variable :

#Engine
config_json: |
    {
        "169.254.40.1": {
            "azimuths": [
                90,
                180,
                270
            ],
            "brand": "reolink",
            "id": 1,
            "name": "mateo-camera-01",
            "poses": [
                1,
                2,
                3
            ],
            "token": "",
            "type": "ptz"
        },
        "169.254.40.2": {
            "azimuth": 17,
            "brand": "reolink",
            "id": 2,
            "name": "mateo-camera-02",
            "poses": [],
            "token": "",
            "type": "static"
        }
    }

The vault file should contains the following variables :

ansible_password: "passwrd" # this is the password of the user used by ansible to connect to the server

##### ENGINE
CAM_USER: "cam_user"
CAM_PWD: "passwrd"
open_vpn_password: "habile"

If the Raspberry Pi connects to a WiFi network, add the WiFi credentials to the vault.yml file (by default, engines )

You will have to encrypt the vault.yml file with your vault_passwrd, use:

  EDITOR=nano ansible-vault encrypt inventory/host_vars/<hostname>/vault.yml

if you want to modify it afterwards, use :

  EDITOR=nano ansible-vault edit inventory/host_vars/<hostname>/vault

After that you can launch the ansible commands you need (check the following section)

Commands

The following commands are available in the Makefile:

  • Ping all hosts: Ping all hosts defined in the Ansible inventory.

    make ping
  • Check watchdog on local Raspberry Pi: Run a playbook to check the watchdog service on the local Raspberry Pi.

    make check-watchdog
  • Check engine service: Run a playbook to check the engine service on specific servers.

    make check-engine
  • Install test engine: Deploy the engine on the test servers. You will need to fill the init_script/.env file

    make install-test-engine
  • Install prod engine: Deploy the engine on the test servers. You will need to fill the init_script/.env file

    make install-engine-fr
  • Start Semaphore: Spin up Semaphore using Docker, a web-based UI for Ansible playbook execution.

    make semaphore-up
  • Stop Semaphore: Stop the Semaphore Docker containers.

    make semaphore-stop

Using Semaphore

Semaphore is a UI tool to manage and run Ansible playbooks:

  1. Start Semaphore using make semaphore-up.
  2. Access the UI at http://localhost:3000 (default credentials: admin / changeme).
  3. Manage playbooks, tasks, and inventory directly from the web interface.

Ansible Directory Structure

This repository follows a typical Ansible directory structure:

  • playbooks/: Contains playbooks that perform specific tasks (e.g., engine deployment, watchdog checks).
  • roles/: Custom roles (if needed) to be reused across playbooks.
  • host_vars/: Directory containing per-host variables and vault files (sensitive information).
  • files/: Contains files (e.g., OpenVPN client configurations) that need to be deployed on the hosts.

Ensure all sensitive data is encrypted using Ansible Vault before pushing it to the repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •