Skip to content

Commit

Permalink
Add ansible linting
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Servin <gary@servin.dev>
  • Loading branch information
garyservin committed Nov 18, 2024
1 parent 549e8b2 commit 6d9be1a
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 96 deletions.
7 changes: 7 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
profile: shared

skip_list:
- fqcn-builtins

exclude_paths:
- .*
21 changes: 21 additions & 0 deletions .github/workflows/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Ansible Linting Tests for the andino_ansible_config repository

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Ansible Lint
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run ansible-lint
uses: ansible/ansible-lint@main
37 changes: 19 additions & 18 deletions .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ concurrency:

jobs:
ansible_deploy_test:
name: Ansible deploy Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04]

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Ansible
run: |
sudo apt update && sudo apt install -y ansible
- name: Install Ansible
run: |
sudo apt update && sudo apt install -y ansible
- name: Install dependencies
run: |
if [ -f requirements.yml ]; then
ansible-galaxy install -r requirements.yml
fi
- name: Install dependencies
run: |
if [ -f requirements.yml ]; then
ansible-galaxy install -r requirements.yml
fi
- name: Run Ansible Playbook
run: ansible-playbook playbook.yml -i inventory --skip-tags 'skip_ci'
- name: Run Ansible Playbook
run: ansible-playbook playbook.yml -i inventory --skip-tags 'skip_ci'

- name: Validate Playbook Syntax
run: ansible-playbook playbook.yml --syntax-check
- name: Validate Playbook Syntax
run: ansible-playbook playbook.yml --syntax-check
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/ansible/ansible-lint
rev: v24.10.0
hooks:
- id: ansible-lint
name: Ansible-lint
description: Run Ansible-lint checks
entry: python3 -m ansiblelint -v --force-color --exclude .*
language: python
pass_filenames: false
always_run: true
additional_dependencies:
- ansible-core>2.13.3
12 changes: 7 additions & 5 deletions playbook.yml → local.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
- hosts:
- name: Andino play installation
hosts:
- localhost
connection: local
roles:
- andino

- hosts:
- name: Post-installation play
hosts:
- localhost
connection: local
tasks:
Expand All @@ -30,9 +32,9 @@

- name: Display warnings
fail:
msg: "{{ warnings }}"
ignore_errors: true
when: warnings is defined and warnings | length > 0
msg: "{{ common_warnings }}"
when: common_warnings is defined and common_warnings | length > 0
ignore_errors: true # noqa: ignore-errors

- name: Display post install message
debug:
Expand Down
10 changes: 5 additions & 5 deletions roles/andino/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
andino_github_repo: https://github.com/Ekumen-OS/andino.git
andino_workspace_path: "/home/{{ ansible_user }}/andino_ws"

install_from_sources: "{{ ('True' if ros2_distribution == 'jazzy' else 'False') | bool }}"
andino_install_from_sources: "{{ ('True' if ros2_distribution == 'jazzy' else 'False') | bool }}"

extra_ros_packages: []
extra_sources: []
andino_extra_ros_packages: []
andino_extra_sources: []

arduino_serial:
andino_arduino_serial:
id_vendor: 1a86
id_product: 7523
name: ttyUSB_ARDUINO

lidar_serial:
andino_lidar_serial:
id_vendor: 10c4
id_product: ea60
name: ttyUSB_LIDAR
14 changes: 5 additions & 9 deletions roles/andino/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
---
galaxy_info:
role_name: andino
author: Gary Servin
description: An Ansible Role that configures and Andino Robot

license: Apache 2.0
license: "Apache 2.0"

min_ansible_version: 2.6

platforms:
- name: Ubuntu
versions:
- noble
min_ansible_version: "2.6"

galaxy_tags:
- andino

dependencies:
- common
- ros2
- role: common
- role: ros2
41 changes: 22 additions & 19 deletions roles/andino/tasks/00-andino_hardware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,76 @@
- v4l-utils
- raspi-config
state: present
update_cache: yes
update_cache: true
cache_valid_time: 3600
become: true

- name: Add user to dialout group to be able to use serial ports and camera
user:
name: "{{ ansible_user }}"
groups: "dialout,plugdev,video"
append: yes
append: true
become: true

- name: Read RPi camera status
shell: vcgencmd get_camera
command: vcgencmd get_camera
register: camera_state
changed_when: false

- name: Check if RPi camera is installed and working
set_fact:
warnings: "{{ warnings + ['RPi camera not detected'] }}"
common_warnings: "{{ common_warnings + ['RPi camera not detected'] }}"
when: "'supported=1 detected=1' not in camera_state"

- name: Configure RPi camera if it isn't detected
command: sudo raspi-config nonint do_camera 1
when: "'supported=1 detected=1' not in camera_state"
changed_when: true

- name: Configure serial port names for Arduino and Lidar
blockinfile:
path: /etc/udev/rules.d/10-usb-serial.rules
create: true
content: |
SUBSYSTEM=="tty", ATTRS{idProduct}=="{{ arduino_serial.id_product }}", ATTRS{idVendor}=="{{ arduino_serial.id_vendor }}", SYMLINK+="ttyUSB_ARDUINO"
SUBSYSTEM=="tty", ATTRS{idProduct}=="{{ lidar_serial.id_product }}", ATTRS{idVendor}=="{{ lidar_serial.id_vendor }}", SYMLINK+="ttyUSB_LIDAR"
template:
src: 10-usb-serial.rules.j2
dest: /etc/udev/rules.d/10-usb-serial.rules
mode: u=rw,g=r,o=r
become: true
register: usb_serial_rules

- name: "Reload udev rules"
shell: udevadm control --reload-rules && udevadm trigger
become: true
when: usb_serial_rules.changed
when: usb_serial_rules.changed # noqa: no-handler
changed_when: true

- name: Verify custom Arduino serial port exists
stat:
path: "/dev/{{ arduino_serial.name }}"
register: arduino_serial_result
failed_when: not arduino_serial_result.stat.exists
path: "/dev/{{ andino_arduino_serial.name }}"
register: andino_arduino_serial_result
failed_when: not andino_arduino_serial_result.stat.exists

- name: Verify custom Lidar serial port exists
stat:
path: "/dev/{{ lidar_serial.name }}"
register: lidar_serial_result
failed_when: not lidar_serial_result.stat.exists
path: "/dev/{{ andino_lidar_serial.name }}"
register: andino_lidar_serial_result
failed_when: not andino_lidar_serial_result.stat.exists

- name: Install PlatformIO dependencies
apt:
name: python3-venv
state: present
update_cache: yes
update_cache: true
cache_valid_time: 3600
become: true

- name: Download PlatformIO installer
ansible.builtin.get_url:
get_url:
url: https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
dest: /tmp/get-platformio.py
mode: "0775"

- name: Install PlatformIO
command: python3 /tmp/get-platformio.py
register: pio_install
changed_when: pio_install.rc == 0

- name: Add PlatformIO to the PATH
lineinfile:
Expand Down
8 changes: 4 additions & 4 deletions roles/andino/tasks/01-andino_debians.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
apt:
name: "{{ 'ros-' + ros2_distribution + '-andino-bringup' }}"
state: present
update_cache: yes
update_cache: true
cache_valid_time: 3600
become: true

- name: Install extra packages
apt:
name: "{{ packages }}"
update_cache: yes
update_cache: true
cache_valid_time: 3600
vars:
packages: "{{ 'ros-' + ros2_distribution + '-' + item }}"
with_items: "{{ extra_ros_packages }}"
when: (extra_ros_packages is defined) and (extra_ros_packages is not none)
with_items: "{{ andino_extra_ros_packages }}"
when: (andino_extra_ros_packages is defined) and (andino_extra_ros_packages is not none)
become: true
12 changes: 7 additions & 5 deletions roles/andino/tasks/02-andino_sources.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
# From: https://github.com/Ekumen-OS/andino/tree/jazzy?tab=readme-ov-file#build-from-source
# From:
# https://github.com/Ekumen-OS/andino/tree/jazzy?tab=readme-ov-file#build-from-source
- name: Install dependencies
apt:
pkg:
Expand All @@ -9,7 +10,7 @@
- python3-rospkg-modules
- python3-rospkg
state: present
update_cache: yes
update_cache: true
cache_valid_time: 3600
become: true

Expand All @@ -18,6 +19,7 @@
dest: "{{ andino_workspace_path }}/src"
state: directory
owner: "{{ ansible_user }}"
mode: "0775"

- name: Clone the Andino Github repository
git:
Expand All @@ -26,7 +28,7 @@
version: "{{ ros2_distribution }}"
accept_hostkey: true
single_branch: true
when: install_from_sources
when: andino_install_from_sources

- name: Install extra source repositories
git:
Expand All @@ -35,8 +37,8 @@
version: "{{ item.branch }}"
accept_hostkey: true
single_branch: true
with_items: "{{ extra_sources }}"
when: extra_sources | length > 0
with_items: "{{ andino_extra_sources }}"
when: andino_extra_sources | length > 0

- name: Install Andino dependencies via rosdep
shell: |
Expand Down
15 changes: 10 additions & 5 deletions roles/andino/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
---
- import_tasks: 00-andino_hardware.yaml
- name: Run Andino Hardware tasks
import_tasks: 00-andino_hardware.yaml
tags: skip_ci
- import_tasks: 01-andino_debians.yaml
when: not install_from_sources
- import_tasks: 02-andino_sources.yaml
when: install_from_sources or extra_sources | length > 0

- name: Install Andino packages via debians
import_tasks: 01-andino_debians.yaml
when: not andino_install_from_sources

- name: Install Andino packages from sources
import_tasks: 02-andino_sources.yaml
when: andino_install_from_sources or andino_extra_sources | length > 0
2 changes: 2 additions & 0 deletions roles/andino/templates/10-usb-serial.rules.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SUBSYSTEM=="tty", ATTRS{idProduct}=="{{ andino_arduino_serial.id_product }}", ATTRS{idVendor}=="{{ andino_arduino_serial.id_vendor }}", SYMLINK+="ttyUSB_ARDUINO"
SUBSYSTEM=="tty", ATTRS{idProduct}=="{{ andino_lidar_serial.id_product }}", ATTRS{idVendor}=="{{ andino_lidar_serial.id_vendor }}", SYMLINK+="ttyUSB_LIDAR"
10 changes: 7 additions & 3 deletions roles/common/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
ansible_user: "{{ lookup('pipe', 'whoami') }}"

target_arch: "{{ 'amd64' if ansible_architecture == 'x86_64' else 'arm64' if ansible_architecture == 'aarch64' else 'armhf' if ansible_architecture == 'armv7l' else ansible_architecture }}"
common_arch_matrix:
x86_64: amd64
aarch64: arm64
armv7l: armhf

ros2_distribution: "{{ 'jazzy' if ansible_distribution_release == 'noble' else 'humble' if ansible_distribution_release == 'jammy' }}"
common_target_arch: "{{ common_arch_matrix[ansible_architecture] }}"

warnings: []
common_warnings: []
6 changes: 6 additions & 0 deletions roles/ros2/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ ros2_gpg_key:
ros2_repository_url: http://packages.ros.org/ros2/ubuntu

ros2_configuration: ros-base

ros2_distribution_matrix:
jammy: humble
noble: jazzy

ros2_distribution: "{{ ros2_distribution_matrix[ansible_distribution_release] }}"
Loading

0 comments on commit 6d9be1a

Please sign in to comment.