mirror of
https://github.com/techno-tim/k3s-ansible.git
synced 2026-10-23 04:12:03 +02:00
- set check_mode: false on the /proc/cpuinfo and /proc/device-tree/model probes, since ansible.builtin.command never executes under --check and returns rc 0 with "Command would have run if not in check mode" - default a missing probe rc to 1 in the raspberry_pi gate so an undefined result cannot be read as "this host is a Raspberry Pi" - add a structural regression test and hook it into pre-commit Without this, site.yml --check marked every x86_64 host as a Raspberry Pi and applied the distro specific setup tasks, failing on Ubuntu with "Destination /boot/firmware/cmdline.txt does not exist".
67 lines
2.7 KiB
YAML
67 lines
2.7 KiB
YAML
---
|
|
# The probes below must run in check mode as well. The command module does not
|
|
# execute under --check, it returns rc 0 with "Command would have run if not in
|
|
# check mode", which would otherwise mark every host as a Raspberry Pi and make
|
|
# check runs apply the distro specific tasks. The rc values mean: 0 matched, 1 no
|
|
# match, 2 the file is absent (no /proc/device-tree on non ARM systems).
|
|
- name: Test for raspberry pi /proc/cpuinfo
|
|
ansible.builtin.command: grep -E "Raspberry Pi|BCM2708|BCM2709|BCM2835|BCM2836" /proc/cpuinfo
|
|
register: grep_cpuinfo_raspberrypi
|
|
failed_when: false
|
|
changed_when: false
|
|
check_mode: false
|
|
|
|
- name: Test for raspberry pi /proc/device-tree/model
|
|
ansible.builtin.command: grep -E "Raspberry Pi" /proc/device-tree/model
|
|
register: grep_device_tree_model_raspberrypi
|
|
failed_when: false
|
|
changed_when: false
|
|
check_mode: false
|
|
|
|
- name: Set raspberry_pi fact to true
|
|
ansible.builtin.set_fact:
|
|
raspberry_pi: true
|
|
when: (grep_cpuinfo_raspberrypi.rc | default(1)) == 0 or (grep_device_tree_model_raspberrypi.rc | default(1)) == 0
|
|
|
|
- name: Set detected_distribution to Raspbian (ARM64 on Raspbian, Debian Buster/Bullseye/Bookworm)
|
|
ansible.builtin.set_fact:
|
|
detected_distribution: Raspbian
|
|
vars:
|
|
allowed_descriptions:
|
|
- "[Rr]aspbian.*"
|
|
- Debian.*buster
|
|
- Debian.*bullseye
|
|
- Debian.*bookworm
|
|
when:
|
|
- ansible_facts.architecture is search("aarch64")
|
|
- raspberry_pi|default(false)
|
|
- ansible_facts.lsb.description|default("") is match(allowed_descriptions | join('|'))
|
|
|
|
- name: Set detected_distribution to Raspbian (ARM64 on Debian Bookworm)
|
|
ansible.builtin.set_fact:
|
|
detected_distribution: Raspbian
|
|
when:
|
|
- ansible_facts.architecture is search("aarch64")
|
|
- raspberry_pi|default(false)
|
|
- ansible_facts.lsb.description|default("") is match("Debian.*bookworm")
|
|
|
|
- name: Set detected_distribution_major_version
|
|
ansible.builtin.set_fact:
|
|
detected_distribution_major_version: "{{ ansible_facts.lsb.major_release }}"
|
|
when:
|
|
- detected_distribution | default("") == "Raspbian"
|
|
|
|
- name: Execute OS related tasks on the Raspberry Pi - {{ action_ }}
|
|
ansible.builtin.include_tasks: "{{ item }}"
|
|
with_first_found:
|
|
- "{{ action_ }}/{{ detected_distribution }}-{{ detected_distribution_major_version }}.yml"
|
|
- "{{ action_ }}/{{ detected_distribution }}.yml"
|
|
- "{{ action_ }}/{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yml"
|
|
- "{{ action_ }}/{{ ansible_facts['distribution'] }}.yml"
|
|
- "{{ action_ }}/default.yml"
|
|
vars:
|
|
action_: >-
|
|
{% if state == "present" %}setup{% else %}teardown{% endif %}
|
|
when:
|
|
- raspberry_pi|default(false)
|