From 53efb429e3143fb749a1ed62e316ddb081e20d42 Mon Sep 17 00:00:00 2001 From: Staf Wagemakers Date: Sun, 16 Aug 2020 10:03:10 +0200 Subject: [PATCH 1/6] moved raspberry specific settings to raspberrypi role --- .../handlers/main.yml | 0 roles/raspberrypi/tasks/main.yml | 48 +++++++++++++++++++ .../tasks/prereq/Raspbian.yml} | 14 ------ .../tasks/prereq/Ubuntu.yml} | 0 roles/raspberrypi/tasks/prereq/default.yml | 1 + site.yml | 3 +- 6 files changed, 50 insertions(+), 16 deletions(-) rename roles/{raspbian => raspberrypi}/handlers/main.yml (100%) create mode 100644 roles/raspberrypi/tasks/main.yml rename roles/{raspbian/tasks/main.yml => raspberrypi/tasks/prereq/Raspbian.yml} (57%) rename roles/{ubuntu/tasks/main.yml => raspberrypi/tasks/prereq/Ubuntu.yml} (100%) create mode 100644 roles/raspberrypi/tasks/prereq/default.yml diff --git a/roles/raspbian/handlers/main.yml b/roles/raspberrypi/handlers/main.yml similarity index 100% rename from roles/raspbian/handlers/main.yml rename to roles/raspberrypi/handlers/main.yml diff --git a/roles/raspberrypi/tasks/main.yml b/roles/raspberrypi/tasks/main.yml new file mode 100644 index 0000000..5979631 --- /dev/null +++ b/roles/raspberrypi/tasks/main.yml @@ -0,0 +1,48 @@ +--- +- name: Test for raspberry pi /proc/cpuinfo + command: grep -E "Raspberry Pi|BCM2708|BCM2709|BCM2835|BCM2836" /proc/cpuinfo + register: grep_cpuinfo_raspberrypi + failed_when: false + changed_when: false + +- name: Test for raspberry pi /proc/device-tree/model + command: grep -E "Raspberry Pi" /proc/device-tree/model + register: grep_device_tree_model_raspberrypi + failed_when: false + changed_when: false + +- name: Set raspberry_pi fact to true + set_fact: + raspberry_pi: true + when: + grep_cpuinfo_raspberrypi.rc == 0 or grep_device_tree_model_raspberrypi.rc == 0 + +- name: Set detected_distribution to Raspbian + set_fact: + detected_distribution: Raspbian + when: + - raspberry_pi|default(false) + - ansible_facts.lsb.id|default("") == "Raspbian" or ansible_facts.lsb.description|default("") is match("[Rr]aspbian.*") + +- name: Set detected_distribution to Raspbian (ARM64 on Debian Buster) + set_fact: + detected_distribution: Raspbian + when: + - ansible_facts.architecture is search("aarch64") + - raspberry_pi|default(false) + - ansible_facts.lsb.description|default("") is match("Debian.*buster") + +- name: Set detected_distribution_major_version + 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 + include_tasks: "{{ item }}" + with_first_found: + - "prereq/{{ detected_distribution }}-{{ detected_distribution_major_version }}.yml" + - "prereq/{{ detected_distribution }}.yml" + - "prereq/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + - "prereq/{{ ansible_distribution }}.yml" + - "prereq/default.yml" diff --git a/roles/raspbian/tasks/main.yml b/roles/raspberrypi/tasks/prereq/Raspbian.yml similarity index 57% rename from roles/raspbian/tasks/main.yml rename to roles/raspberrypi/tasks/prereq/Raspbian.yml index 04c931a..42bfe7d 100644 --- a/roles/raspbian/tasks/main.yml +++ b/roles/raspberrypi/tasks/prereq/Raspbian.yml @@ -1,13 +1,4 @@ --- -- name: Test for Raspbian - set_fact: - raspbian: '{% if - ( ansible_facts.architecture is search("arm") and - ansible_facts.lsb.description is match("[Rr]aspbian.*[Bb]uster") ) or - ( ansible_facts.architecture is search("aarch64") and - ansible_facts.lsb.description is match("Debian.*buster") or - ansible_facts.lsb.description is match("[Rr]aspbian.*[Bb]uster") ) %}true{% else %}false{% endif %}' - - name: Activating cgroup support lineinfile: path: /boot/cmdline.txt @@ -15,13 +6,10 @@ line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' backrefs: true notify: reboot - when: - - raspbian is true - name: Flush iptables before changing to iptables-legacy iptables: flush: true - when: raspbian changed_when: false # iptables flush always returns changed - name: Changing to iptables-legacy @@ -29,11 +17,9 @@ path: /usr/sbin/iptables-legacy name: iptables register: ip4_legacy - when: raspbian - name: Changing to ip6tables-legacy alternatives: path: /usr/sbin/ip6tables-legacy name: ip6tables register: ip6_legacy - when: raspbian diff --git a/roles/ubuntu/tasks/main.yml b/roles/raspberrypi/tasks/prereq/Ubuntu.yml similarity index 100% rename from roles/ubuntu/tasks/main.yml rename to roles/raspberrypi/tasks/prereq/Ubuntu.yml diff --git a/roles/raspberrypi/tasks/prereq/default.yml b/roles/raspberrypi/tasks/prereq/default.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/raspberrypi/tasks/prereq/default.yml @@ -0,0 +1 @@ +--- diff --git a/site.yml b/site.yml index 8862e96..31cc96e 100644 --- a/site.yml +++ b/site.yml @@ -6,8 +6,7 @@ roles: - role: prereq - role: download - - role: raspbian - - role: ubuntu + - role: raspberrypi - hosts: master become: yes From a5782b1d61ff9e306efcf35f56f384f93bcf075c Mon Sep 17 00:00:00 2001 From: Staf Wagemakers Date: Sun, 16 Aug 2020 10:11:15 +0200 Subject: [PATCH 2/6] * updated description * use handler for the reboot * removed ARM cpu detection --- roles/raspberrypi/tasks/prereq/Ubuntu.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/roles/raspberrypi/tasks/prereq/Ubuntu.yml b/roles/raspberrypi/tasks/prereq/Ubuntu.yml index 72d1eef..742fc21 100644 --- a/roles/raspberrypi/tasks/prereq/Ubuntu.yml +++ b/roles/raspberrypi/tasks/prereq/Ubuntu.yml @@ -1,18 +1,8 @@ --- -- name: Enable cgroup via boot commandline if not already enabled for Ubuntu on ARM +- name: Enable cgroup via boot commandline if not already enabled for Ubuntu on a Raspberry Pi lineinfile: path: /boot/firmware/cmdline.txt backrefs: yes regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' - when: - - ansible_distribution == 'Ubuntu' - - ( ansible_facts.architecture is search("arm") or - ansible_facts.architecture is search("aarch64") ) - -- name: Reboot to enable cgroups for Ubuntu on ARM - reboot: - when: - - ansible_distribution == 'Ubuntu' - - ( ansible_facts.architecture is search("arm") or - ansible_facts.architecture is search("aarch64") ) + notify: reboot From 98473e2b09c8accfe4cae69b62b832e25dfc26f0 Mon Sep 17 00:00:00 2001 From: Staf Wagemakers Date: Sun, 16 Aug 2020 12:52:25 +0200 Subject: [PATCH 3/6] only execute PI os specific settings on a PI --- roles/raspberrypi/tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/raspberrypi/tasks/main.yml b/roles/raspberrypi/tasks/main.yml index 5979631..ca3881f 100644 --- a/roles/raspberrypi/tasks/main.yml +++ b/roles/raspberrypi/tasks/main.yml @@ -46,3 +46,5 @@ - "prereq/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" - "prereq/{{ ansible_distribution }}.yml" - "prereq/default.yml" + when: + - raspberry_pi|default(false) From d2b420588e6456c7fa9e4a48ded9c12f741ef87c Mon Sep 17 00:00:00 2001 From: Staf Wagemakers Date: Sun, 16 Aug 2020 20:38:12 +0200 Subject: [PATCH 4/6] support for CentOS on the Raspberry Pi added --- roles/raspberrypi/tasks/prereq/CentOS.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 roles/raspberrypi/tasks/prereq/CentOS.yml diff --git a/roles/raspberrypi/tasks/prereq/CentOS.yml b/roles/raspberrypi/tasks/prereq/CentOS.yml new file mode 100644 index 0000000..af83564 --- /dev/null +++ b/roles/raspberrypi/tasks/prereq/CentOS.yml @@ -0,0 +1,8 @@ +--- +- name: Enable cgroup via boot commandline if not already enabled for Centos + lineinfile: + path: /boot/cmdline.txt + backrefs: yes + regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' + line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' + notify: reboot From c65736775564cdbeefefddb85ac8da300c87c20e Mon Sep 17 00:00:00 2001 From: Staf Wagemakers Date: Sun, 16 Aug 2020 21:53:00 +0200 Subject: [PATCH 5/6] lint errors corrected --- roles/raspberrypi/tasks/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/roles/raspberrypi/tasks/main.yml b/roles/raspberrypi/tasks/main.yml index ca3881f..7da0519 100644 --- a/roles/raspberrypi/tasks/main.yml +++ b/roles/raspberrypi/tasks/main.yml @@ -20,9 +20,10 @@ - name: Set detected_distribution to Raspbian set_fact: detected_distribution: Raspbian - when: - - raspberry_pi|default(false) - - ansible_facts.lsb.id|default("") == "Raspbian" or ansible_facts.lsb.description|default("") is match("[Rr]aspbian.*") + when: > + raspberry_pi|default(false) and + ( ansible_facts.lsb.id|default("") == "Raspbian" or + ansible_facts.lsb.description|default("") is match("[Rr]aspbian.*") ) - name: Set detected_distribution to Raspbian (ARM64 on Debian Buster) set_fact: From f8aebf8ec6ec92be9dac5af6e96578646577c754 Mon Sep 17 00:00:00 2001 From: Staf Wagemakers Date: Sun, 16 Aug 2020 21:55:34 +0200 Subject: [PATCH 6/6] trailing space removed --- roles/raspberrypi/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/raspberrypi/tasks/main.yml b/roles/raspberrypi/tasks/main.yml index 7da0519..b80c91f 100644 --- a/roles/raspberrypi/tasks/main.yml +++ b/roles/raspberrypi/tasks/main.yml @@ -21,7 +21,7 @@ set_fact: detected_distribution: Raspbian when: > - raspberry_pi|default(false) and + raspberry_pi|default(false) and ( ansible_facts.lsb.id|default("") == "Raspbian" or ansible_facts.lsb.description|default("") is match("[Rr]aspbian.*") )