From f99f174248527a60e94740f8c71a86e152861df7 Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Thu, 16 Apr 2026 10:41:42 +0000 Subject: [PATCH] Created ansible script to configure target controller --- .gitignore | 16 +++++++++++ ansible/README.md | 60 ++++++++++++++++++++++++++++++++++++++++ ansible/inventory.ini | 5 ++++ ansible/requirements.yml | 2 ++ ansible/setup_robot.yml | 16 +++++++++++ 5 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 ansible/README.md create mode 100644 ansible/inventory.ini create mode 100644 ansible/requirements.yml create mode 100644 ansible/setup_robot.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03b4ab6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# VS Code +.vscode/browse.vc.db +.vscode/browse.vc.db-shm +.vscode/browse.vc.db-wal +.vscode/c_cpp_properties.json + +# colcon build artefacts +build/ +install/ +log/ + +# Python +__pycache__/ +*.py[cod] +*.egg-info/ +dist/ diff --git a/ansible/README.md b/ansible/README.md new file mode 100644 index 0000000..098640c --- /dev/null +++ b/ansible/README.md @@ -0,0 +1,60 @@ +# Robot Setup — Ansible + +Automates provisioning of the Raspbot V2 target (`raspbot-v2.local`). + +## What it does + +| Step | Detail | +|---|---| +| Enable SPI | Runs `raspi-config nonint do_spi 0` so the hardware interface is available at boot | +| Install Docker | Uses the [`geerlingguy.docker`](https://galaxy.ansible.com/geerlingguy/docker) role | + +## Prerequisites + +- Ansible installed on your local machine (`pip install ansible`) +- SSH access to `raspbot-v2.local` (key-based auth recommended) +- The target is running Raspberry Pi OS + +## Configuration + +Before running the playbook, set `robot_user` in `inventory.ini` to the non-root user account on the robot (i.e. the username you configured during imaging): + +```ini +[raspbot:vars] +robot_user=matt +``` + +This user will be added to the `docker` group so that Docker commands can be run without `sudo`. + +## Usage + +**1. Install the required role:** + +```bash +ansible-galaxy install -r ansible/requirements.yml +``` + +**2. Run the playbook:** + +The playbook runs tasks as root (`become: true`), so Ansible needs the sudo password for the remote user. Always include `-K`: + +```bash +ansible-playbook -i ansible/inventory.ini ansible/setup_robot.yml -K +``` + +If you haven't set up SSH key-based auth yet, also add `-k` to prompt for the SSH password: + +```bash +ansible-playbook -i ansible/inventory.ini ansible/setup_robot.yml -k -K +``` + +The SSH user is taken from `robot_user` in `inventory.ini`, so there is no need to pass `-u` separately. + +## Files + +``` +ansible/ +├── inventory.ini # Defines the raspbot-v2.local host +├── requirements.yml # Ansible Galaxy role dependencies +└── setup_robot.yml # Main playbook +``` diff --git a/ansible/inventory.ini b/ansible/inventory.ini new file mode 100644 index 0000000..1df50af --- /dev/null +++ b/ansible/inventory.ini @@ -0,0 +1,5 @@ +[raspbot] +raspbot-v2.local + +[raspbot:vars] +robot_user=matt diff --git a/ansible/requirements.yml b/ansible/requirements.yml new file mode 100644 index 0000000..d6ae8f7 --- /dev/null +++ b/ansible/requirements.yml @@ -0,0 +1,2 @@ +roles: + - name: geerlingguy.docker diff --git a/ansible/setup_robot.yml b/ansible/setup_robot.yml new file mode 100644 index 0000000..5041546 --- /dev/null +++ b/ansible/setup_robot.yml @@ -0,0 +1,16 @@ +--- +- name: Setup robot + hosts: raspbot + become: true + + vars: + docker_users: + - "{{ robot_user }}" + + pre_tasks: + - name: Enable SPI via raspi-config + command: raspi-config nonint do_spi 0 + changed_when: false + + roles: + - geerlingguy.docker