From 52252044f100b9aaa7df7e84e225c9c36f8bf9c4 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 15 Mar 2022 12:47:39 -0500 Subject: [PATCH 1/5] generalize wifi dependencies based on hardware present --- roles/1-prep/tasks/hardware.yml | 16 ++++++++++++++++ roles/1-prep/tasks/raspberry_pi.yml | 12 +----------- roles/1-prep/tasks/wifi.yml | 14 ++++++++++++++ roles/2-common/tasks/network.yml | 3 +-- 4 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 roles/1-prep/tasks/wifi.yml diff --git a/roles/1-prep/tasks/hardware.yml b/roles/1-prep/tasks/hardware.yml index 2650c7217..7b3f6fa5a 100644 --- a/roles/1-prep/tasks/hardware.yml +++ b/roles/1-prep/tasks/hardware.yml @@ -1,6 +1,22 @@ ## DISCOVER PLATFORMS ###### # Put conditional actions for hardware platforms here +- name: Look for any wireless devices present + shell: "ls -la /sys/class/net/*/phy80211 | awk -F / '{print $5}'" + register: has_wifi_device + ignore_errors: True + changed_when: False + +- name: Set has_wireless, if found + set_fact: + has_wireless: True + when: has_wifi_device.stdout is defined and item|trim != "" + with_items: + - "{{ has_wifi_device.stdout_lines }}" + +- include_tasks: wifi.yml + when: has_wireless is defined + - include_tasks: raspberry_pi.yml when: first_run and rpi_model != "none" diff --git a/roles/1-prep/tasks/raspberry_pi.yml b/roles/1-prep/tasks/raspberry_pi.yml index bc54f58af..745ce60b9 100644 --- a/roles/1-prep/tasks/raspberry_pi.yml +++ b/roles/1-prep/tasks/raspberry_pi.yml @@ -38,22 +38,12 @@ - name: '2021-07-27: SEE ALSO 4-5 networking packages LATER installed by https://github.com/iiab/iiab/blob/master/roles/2-common/tasks/network.yml' meta: noop -# 2021-07-27 explanation from @jvonau: The 3 BELOW (iw, rfkill, wireless-tools) -# are provided by RaspiOS. Ubuntu|Debian on the other hand are hit or miss: -# desktops might have some/all 3 preinstalled, while servers tend not to have -# these present at all, but are needed to be installed if you want to take full -# advantage of WiFi on Ubuntu and friends -- but it's only enforced on RPi -# hardware where we know in advance of the likelihood of WiFi being present. - -- name: 'Install packages: cloud-guest-utils, dphys-swapfile, fake-hwclock, iw, rfkill, wireless-tools' +- name: 'Install packages: cloud-guest-utils, dphys-swapfile, fake-hwclock' package: name: - cloud-guest-utils # Contains 'growpart' for resizing a partition during boot, which is normally done with the aid of cloud-init - dphys-swapfile # 2021-07-27: RaspiOS installs this regardless -- autogenerate and use a swap file - fake-hwclock # 2021-07-27: RaspiOS installs this regardless -- save/restore system clock on machines without working RTC hardware - - iw # 2021-07-27: RaspiOS installs this regardless -- configure Linux wireless devices -- hard dependence for ap0 creation, SEE https://github.com/iiab/iiab/blob/master/roles/network/templates/hostapd/iiab-clone-wifi.service.j2 - - rfkill # 2021-07-27: RaspiOS installs this regardless -- enable & disable wireless devices - - wireless-tools # 2021-07-27: RaspiOS installs this regardless -- manipulate Linux Wireless Extensions state: present diff --git a/roles/1-prep/tasks/wifi.yml b/roles/1-prep/tasks/wifi.yml new file mode 100644 index 000000000..718376ab4 --- /dev/null +++ b/roles/1-prep/tasks/wifi.yml @@ -0,0 +1,14 @@ +# 2021-07-27 explanation from @jvonau: The 3 BELOW (iw, rfkill, wireless-tools) +# are provided by RaspiOS. Ubuntu|Debian on the other hand are hit or miss: +# desktops might have some/all 3 preinstalled, while servers tend not to have +# these present at all, but are needed to be installed if you want to take full +# advantage of WiFi on Ubuntu and friends + +- name: 'Install packages: hostapd, iw, rfkill, wireless-tools' + package: + name: + - hostapd # IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator -- has its service masked out of the box, and only used when IIAB's network roles detects the presence of WiFi and an AP is desired + - iw # 2021-07-27: RaspiOS installs this regardless -- configure Linux wireless devices -- hard dependence for ap0 creation, SEE https://github.com/iiab/iiab/blob/master/roles/network/templates/hostapd/iiab-clone-wifi.service.j2 + - rfkill # 2021-07-27: RaspiOS installs this regardless -- enable & disable wireless devices + - wireless-tools # 2021-07-27: RaspiOS installs this regardless -- manipulate Linux Wireless Extensions + state: present diff --git a/roles/2-common/tasks/network.yml b/roles/2-common/tasks/network.yml index 435c0bb1f..faff74dde 100644 --- a/roles/2-common/tasks/network.yml +++ b/roles/2-common/tasks/network.yml @@ -10,10 +10,9 @@ state: present when: not is_raspbian -- name: 'Install network packages: hostapd, iproute2, iptables-persistent, netmask -- later used by https://github.com/iiab/iiab/tree/master/roles/network' +- name: 'Install network packages: iproute2, iptables-persistent, netmask -- later used by https://github.com/iiab/iiab/tree/master/roles/network' package: name: - - hostapd # IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator -- has its service masked out of the box, and only used when IIAB's network roles detects the presence of WiFi and an AP is desired - iproute2 # 2021-07-27: RaspiOS installs this regardless -- the new networking and traffic control tools, meant to replace net-tools - iptables-persistent # Boot-time loader for netfilter rules, iptables (firewall) plugin -- however Netfilter / nftables is ever moving forward so keep an eye on it! - netmask # Handy utility -- helps determine network masks From 03a630b199ad43731e9be7be8aeed106f13ed910 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 15 Mar 2022 14:01:02 -0500 Subject: [PATCH 2/5] leave hostapd as was - has an unconditional systemd call in hostapd.yml --- roles/1-prep/tasks/wifi.yml | 3 +-- roles/2-common/tasks/network.yml | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/1-prep/tasks/wifi.yml b/roles/1-prep/tasks/wifi.yml index 718376ab4..f246fbea0 100644 --- a/roles/1-prep/tasks/wifi.yml +++ b/roles/1-prep/tasks/wifi.yml @@ -4,10 +4,9 @@ # these present at all, but are needed to be installed if you want to take full # advantage of WiFi on Ubuntu and friends -- name: 'Install packages: hostapd, iw, rfkill, wireless-tools' +- name: 'Install packages: iw, rfkill, wireless-tools' package: name: - - hostapd # IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator -- has its service masked out of the box, and only used when IIAB's network roles detects the presence of WiFi and an AP is desired - iw # 2021-07-27: RaspiOS installs this regardless -- configure Linux wireless devices -- hard dependence for ap0 creation, SEE https://github.com/iiab/iiab/blob/master/roles/network/templates/hostapd/iiab-clone-wifi.service.j2 - rfkill # 2021-07-27: RaspiOS installs this regardless -- enable & disable wireless devices - wireless-tools # 2021-07-27: RaspiOS installs this regardless -- manipulate Linux Wireless Extensions diff --git a/roles/2-common/tasks/network.yml b/roles/2-common/tasks/network.yml index faff74dde..435c0bb1f 100644 --- a/roles/2-common/tasks/network.yml +++ b/roles/2-common/tasks/network.yml @@ -10,9 +10,10 @@ state: present when: not is_raspbian -- name: 'Install network packages: iproute2, iptables-persistent, netmask -- later used by https://github.com/iiab/iiab/tree/master/roles/network' +- name: 'Install network packages: hostapd, iproute2, iptables-persistent, netmask -- later used by https://github.com/iiab/iiab/tree/master/roles/network' package: name: + - hostapd # IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator -- has its service masked out of the box, and only used when IIAB's network roles detects the presence of WiFi and an AP is desired - iproute2 # 2021-07-27: RaspiOS installs this regardless -- the new networking and traffic control tools, meant to replace net-tools - iptables-persistent # Boot-time loader for netfilter rules, iptables (firewall) plugin -- however Netfilter / nftables is ever moving forward so keep an eye on it! - netmask # Handy utility -- helps determine network masks From 4a1e5a89ab80ac2c8ddbe6c6d72477978371bba3 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Mar 2022 18:30:19 -0400 Subject: [PATCH 3/5] 1-prep/tasks/hardware.yml: Cleaner modularization & assoc fixups --- roles/1-prep/tasks/hardware.yml | 40 ++----------------- roles/1-prep/tasks/install-expand-rootfs.yml | 20 ++++++++++ roles/1-prep/tasks/internal-wifi.yml | 33 +++++++++++++++ roles/1-prep/tasks/raspberry_pi.yml | 35 +++++----------- roles/1-prep/tasks/wifi.yml | 13 ------ .../templates/iiab-expand-rootfs.service | 4 +- roles/2-common/tasks/network.yml | 2 +- roles/2-common/tasks/packages.yml | 2 +- roles/iiab-admin/tasks/access.yml | 6 --- roles/iiab-admin/tasks/access.yml.unused | 6 +++ roles/iiab-admin/tasks/main.yml | 8 +++- 11 files changed, 84 insertions(+), 85 deletions(-) create mode 100644 roles/1-prep/tasks/install-expand-rootfs.yml create mode 100644 roles/1-prep/tasks/internal-wifi.yml delete mode 100644 roles/1-prep/tasks/wifi.yml delete mode 100644 roles/iiab-admin/tasks/access.yml create mode 100644 roles/iiab-admin/tasks/access.yml.unused diff --git a/roles/1-prep/tasks/hardware.yml b/roles/1-prep/tasks/hardware.yml index c397223e2..b28623884 100644 --- a/roles/1-prep/tasks/hardware.yml +++ b/roles/1-prep/tasks/hardware.yml @@ -1,43 +1,9 @@ -- name: Install packages 'parted' and 'cloud-guest-utils' (so /usr/bin/growpart is available for expanding rootfs partition during boot) - package: - name: - - parted # 2022-03-15: RasPiOS and Ubuntu install this regardless -- so rarely nec but just in case. - - cloud-guest-utils # 2022-03-15: For growpart command -- though RasPiOS currently doesn't need this, as raspi-config's do_expand_rootfs() instead uses fdisk. Ubuntu pre-installs cloud-guest-utils, for use with cloud-init. - state: present - -- name: "Install from templates: /usr/sbin/iiab-expand-rootfs, /etc/systemd/system/iiab-expand-rootfs.service" - template: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - mode: "{{ item.mode }}" - with_items: - - { src: 'iiab-expand-rootfs', dest: '/usr/sbin/', mode: '0755' } - - { src: 'iiab-expand-rootfs.service', dest: '/etc/systemd/system/', mode: '0644' } - -- name: Enable /etc/systemd/system/iiab-expand-rootfs.service - systemd: - name: iiab-expand-rootfs - enabled: yes +- include_tasks: install-expand-rootfs.yml -## DISCOVER PLATFORMS ###### -# Put conditional actions for hardware platforms here +# Conditional hardware actions below: -- name: Look for any wireless devices present - shell: "ls -la /sys/class/net/*/phy80211 | awk -F / '{print $5}'" - register: has_wifi_device - ignore_errors: True - changed_when: False - -- name: Set has_wireless, if found - set_fact: - has_wireless: True - when: has_wifi_device.stdout is defined and item|trim != "" - with_items: - - "{{ has_wifi_device.stdout_lines }}" - -- include_tasks: wifi.yml - when: has_wireless is defined +- include_tasks: internal-wifi.yml - include_tasks: raspberry_pi.yml when: first_run and rpi_model != "none" diff --git a/roles/1-prep/tasks/install-expand-rootfs.yml b/roles/1-prep/tasks/install-expand-rootfs.yml new file mode 100644 index 000000000..a2f2d5aa9 --- /dev/null +++ b/roles/1-prep/tasks/install-expand-rootfs.yml @@ -0,0 +1,20 @@ +- name: Install packages 'parted' and 'cloud-guest-utils' (so /usr/bin/growpart is available for expanding rootfs partition during boot) + package: + name: + - parted # 2022-03-15: RasPiOS and Ubuntu install this regardless -- so rarely nec but just in case. + - cloud-guest-utils # 2022-03-15: For growpart command -- though RasPiOS currently doesn't need this, as raspi-config's do_expand_rootfs() instead uses fdisk. Ubuntu pre-installs cloud-guest-utils, for use with cloud-init. + state: present + +- name: "Install from templates: /usr/sbin/iiab-expand-rootfs, /etc/systemd/system/iiab-expand-rootfs.service" + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + with_items: + - { src: 'iiab-expand-rootfs', dest: '/usr/sbin/', mode: '0755' } + - { src: 'iiab-expand-rootfs.service', dest: '/etc/systemd/system/', mode: '0644' } + +- name: Enable /etc/systemd/system/iiab-expand-rootfs.service + systemd: + name: iiab-expand-rootfs + enabled: yes diff --git a/roles/1-prep/tasks/internal-wifi.yml b/roles/1-prep/tasks/internal-wifi.yml new file mode 100644 index 000000000..24422d36b --- /dev/null +++ b/roles/1-prep/tasks/internal-wifi.yml @@ -0,0 +1,33 @@ +- name: Look for any wireless devices present + shell: "ls -la /sys/class/net/*/phy80211 | cut -d/ -f5" + register: has_wifi_device + ignore_errors: True + changed_when: False + +- name: Set internal_wifi, if found + set_fact: + internal_wifi: True + when: has_wifi_device.stdout is defined and item|trim != "" + with_items: + - "{{ has_wifi_device.stdout_lines }}" + +# 2021-07-27 explanation from @jvonau: The 3 BELOW (iw, rfkill, wireless-tools) +# are provided by RasPiOS. Ubuntu|Debian on the other hand are hit or miss: +# desktops might have some/all 3 preinstalled, while servers tend not to have +# these present at all, but are needed to be installed if you want to take full +# advantage of WiFi on Ubuntu and friends. + +- name: 'Install packages: iw, rfkill, wireless-tools' + package: + name: + - iw # 2021-07-27: RasPiOS installs this regardless -- configure Linux wireless devices -- hard dependence for ap0 creation, SEE https://github.com/iiab/iiab/blob/master/roles/network/templates/hostapd/iiab-clone-wifi.service.j2 + - rfkill # 2021-07-27: RasPiOS installs this regardless -- enable & disable wireless devices + - wireless-tools # 2021-07-27: RasPiOS installs this regardless -- manipulate Linux Wireless Extensions + state: present + when: internal_wifi is defined + +- name: '2021-07-27: SEE ALSO ~4 networking packages LATER installed by https://github.com/iiab/iiab/blob/master/roles/2-common/tasks/packages.yml' + meta: noop + +- name: '2021-07-27: SEE ALSO 4-5 networking packages LATER installed by https://github.com/iiab/iiab/blob/master/roles/2-common/tasks/network.yml' + meta: noop diff --git a/roles/1-prep/tasks/raspberry_pi.yml b/roles/1-prep/tasks/raspberry_pi.yml index 90a312521..fbc8cc784 100644 --- a/roles/1-prep/tasks/raspberry_pi.yml +++ b/roles/1-prep/tasks/raspberry_pi.yml @@ -4,9 +4,6 @@ template: src: 92-rtc-i2c.rules dest: /etc/udev/rules.d/92-rtc-i2c.rules - #owner: root - #group: root - #mode: 0644 when: rtc_id is defined and rtc_id != "none" # RTC requires a change to the device tree (and reboot) @@ -24,30 +21,12 @@ state: present when: rtc_id is defined and rtc_id != "none" and is_ubuntu # CLARIF: Ubuntu runs increasingly well on RPi hardware, starting in 2020 especially -#- name: Enable bluetooth in /boot/firmware/syscfg.txt on Ubuntu (needs reboot) -# lineinfile: -# path: /boot/firmware/syscfg.txt -# regexp: '^include*' -# line: 'include btcfg.txt' -# when: is_ubuntu - -- name: '2021-07-27: SEE ALSO ~4 networking packages LATER installed by https://github.com/iiab/iiab/blob/master/roles/2-common/tasks/packages.yml' - meta: noop - -- name: '2021-07-27: SEE ALSO 4-5 networking packages LATER installed by https://github.com/iiab/iiab/blob/master/roles/2-common/tasks/network.yml' - meta: noop - -# 2022-03-15: This section is effectively now useless on RasPiOS (but apparently -# serves a purpose on Ubuntu on RPi, where it installs dphys-swapfile and -# fake-hwclock). Still: @jvonau's above explanation of other OS's / other HW -# suggest this code should possibly move in future, to helps others too? - -- name: 'Install packages: dphys-swapfile, fake-hwclock' +- name: 'Install packages: fake-hwclock, dphys-swapfile' package: name: - - dphys-swapfile # 2021-03-15: For Ubuntu on RPi? RasPiOS installs this regardless -- autogenerate and use a swap file - - fake-hwclock # 2021-03-15: For Ubuntu on RPi? RasPiOS installs this regardless -- save/restore system clock on machines without working RTC hardware + - fake-hwclock # 2021-03-15: Missing on Ubuntu etc. RasPiOS installs this regardless -- to save/restore system clock on machines w/o working RTC (above). + - dphys-swapfile # 2021-03-15: Missing on Ubuntu etc. RasPiOS installs this regardless -- to autogenerate and use a swap file (below). state: present - name: Increase swap file size (to CONF_SWAPSIZE={{ pi_swap_file_size }} in /etc/dphys-swapfile) as kalite pip download fails @@ -61,3 +40,11 @@ systemd: # Had been...a rare/legacy service that was NOT systemd name: dphys-swapfile state: restarted + + +#- name: Enable bluetooth in /boot/firmware/syscfg.txt on Ubuntu (needs reboot) +# lineinfile: +# path: /boot/firmware/syscfg.txt +# regexp: '^include*' +# line: 'include btcfg.txt' +# when: is_ubuntu diff --git a/roles/1-prep/tasks/wifi.yml b/roles/1-prep/tasks/wifi.yml deleted file mode 100644 index f246fbea0..000000000 --- a/roles/1-prep/tasks/wifi.yml +++ /dev/null @@ -1,13 +0,0 @@ -# 2021-07-27 explanation from @jvonau: The 3 BELOW (iw, rfkill, wireless-tools) -# are provided by RaspiOS. Ubuntu|Debian on the other hand are hit or miss: -# desktops might have some/all 3 preinstalled, while servers tend not to have -# these present at all, but are needed to be installed if you want to take full -# advantage of WiFi on Ubuntu and friends - -- name: 'Install packages: iw, rfkill, wireless-tools' - package: - name: - - iw # 2021-07-27: RaspiOS installs this regardless -- configure Linux wireless devices -- hard dependence for ap0 creation, SEE https://github.com/iiab/iiab/blob/master/roles/network/templates/hostapd/iiab-clone-wifi.service.j2 - - rfkill # 2021-07-27: RaspiOS installs this regardless -- enable & disable wireless devices - - wireless-tools # 2021-07-27: RaspiOS installs this regardless -- manipulate Linux Wireless Extensions - state: present diff --git a/roles/1-prep/templates/iiab-expand-rootfs.service b/roles/1-prep/templates/iiab-expand-rootfs.service index 4ac36fa42..f7f68402c 100644 --- a/roles/1-prep/templates/iiab-expand-rootfs.service +++ b/roles/1-prep/templates/iiab-expand-rootfs.service @@ -5,7 +5,9 @@ Description=Root Filesystem Auto-Expander Environment=TERM=linux Type=oneshot ExecStart=/usr/sbin/iiab-expand-rootfs -StandardError=syslog +# "Standard output type syslog is obsolete" +# StandardError=syslog +# WHEREAS StandardError=journal is the default, per https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput= RemainAfterExit=no [Install] diff --git a/roles/2-common/tasks/network.yml b/roles/2-common/tasks/network.yml index 435c0bb1f..f7c560f8b 100644 --- a/roles/2-common/tasks/network.yml +++ b/roles/2-common/tasks/network.yml @@ -1,4 +1,4 @@ -- name: '2021-07-27: SEE ALSO ~3 networking packages EARLIER installed by https://github.com/iiab/iiab/blob/master/roles/1-prep/tasks/raspberry_pi.yml' +- name: '2021-07-27: SEE ALSO ~3 networking packages EARLIER installed by https://github.com/iiab/iiab/blob/master/roles/1-prep/tasks/internal-wifi.yml' meta: noop - name: '2021-07-27: SEE ALSO ~4 networking packages EARLIER installed by https://github.com/iiab/iiab/blob/master/roles/2-common/tasks/packages.yml' diff --git a/roles/2-common/tasks/packages.yml b/roles/2-common/tasks/packages.yml index 81bc35c94..2f5694d31 100644 --- a/roles/2-common/tasks/packages.yml +++ b/roles/2-common/tasks/packages.yml @@ -1,4 +1,4 @@ -- name: '2021-07-27: SEE ALSO ~3 networking packages EARLIER installed by https://github.com/iiab/iiab/blob/master/roles/1-prep/tasks/raspberry_pi.yml' +- name: '2021-07-27: SEE ALSO ~3 networking packages EARLIER installed by https://github.com/iiab/iiab/blob/master/roles/1-prep/tasks/internal-wifi.yml' meta: noop - name: '2021-07-27: SEE ALSO 4-5 networking packages LATER installed by https://github.com/iiab/iiab/blob/master/roles/2-common/tasks/network.yml' diff --git a/roles/iiab-admin/tasks/access.yml b/roles/iiab-admin/tasks/access.yml deleted file mode 100644 index e7281c4dc..000000000 --- a/roles/iiab-admin/tasks/access.yml +++ /dev/null @@ -1,6 +0,0 @@ -- name: "Install text mode packages, useful during remote access: screen, lynx" - package: - name: - - lynx - - screen - state: present diff --git a/roles/iiab-admin/tasks/access.yml.unused b/roles/iiab-admin/tasks/access.yml.unused new file mode 100644 index 000000000..639a3d8a6 --- /dev/null +++ b/roles/iiab-admin/tasks/access.yml.unused @@ -0,0 +1,6 @@ +- name: "Install text-mode packages, useful during remote access: lynx, screen" + package: + name: + - lynx + - screen + state: present diff --git a/roles/iiab-admin/tasks/main.yml b/roles/iiab-admin/tasks/main.yml index ce4451003..f2a048e33 100644 --- a/roles/iiab-admin/tasks/main.yml +++ b/roles/iiab-admin/tasks/main.yml @@ -2,8 +2,12 @@ # https://github.com/iiab/iiab/blob/master/roles/iiab-admin/README.rst -- name: Install lynx, screen - include_tasks: access.yml +- name: "Install text-mode packages, useful during remote access: lynx, screen" + package: + name: + - lynx + - screen + state: present - name: Install sudo & /etc/sudoers with logging to /var/log/sudo.log include_tasks: sudo-prereqs.yml From 566bef36c8c5e1966b3f450ec979fd477c180497 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Mar 2022 19:45:29 -0400 Subject: [PATCH 4/5] 1-prep/tasks/internal-wifi.yml: Ansible code touch-ups --- roles/1-prep/tasks/internal-wifi.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/roles/1-prep/tasks/internal-wifi.yml b/roles/1-prep/tasks/internal-wifi.yml index 24422d36b..2751dfd13 100644 --- a/roles/1-prep/tasks/internal-wifi.yml +++ b/roles/1-prep/tasks/internal-wifi.yml @@ -1,5 +1,5 @@ - name: Look for any wireless devices present - shell: "ls -la /sys/class/net/*/phy80211 | cut -d/ -f5" + shell: ls -la /sys/class/net/*/phy80211 | cut -d/ -f5 register: has_wifi_device ignore_errors: True changed_when: False @@ -7,9 +7,7 @@ - name: Set internal_wifi, if found set_fact: internal_wifi: True - when: has_wifi_device.stdout is defined and item|trim != "" - with_items: - - "{{ has_wifi_device.stdout_lines }}" + when: has_wifi_device is defined and has_wifi_device.stdout | trim != "" # 2021-07-27 explanation from @jvonau: The 3 BELOW (iw, rfkill, wireless-tools) # are provided by RasPiOS. Ubuntu|Debian on the other hand are hit or miss: From 67ebb0b2a114ea355868d649d64797887ffe8422 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Mar 2022 22:17:36 -0400 Subject: [PATCH 5/5] Cleaner internal-wifi.yml + install-expand-rootfs.yml --- roles/1-prep/tasks/install-expand-rootfs.yml | 6 +++--- roles/1-prep/tasks/internal-wifi.yml | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/roles/1-prep/tasks/install-expand-rootfs.yml b/roles/1-prep/tasks/install-expand-rootfs.yml index a2f2d5aa9..54d77c55b 100644 --- a/roles/1-prep/tasks/install-expand-rootfs.yml +++ b/roles/1-prep/tasks/install-expand-rootfs.yml @@ -1,7 +1,7 @@ -- name: Install packages 'parted' and 'cloud-guest-utils' (so /usr/bin/growpart is available for expanding rootfs partition during boot) +- name: Install packages 'parted' and 'cloud-guest-utils' (for /usr/bin/growpart, though raspi-config uses fdisk) package: name: - - parted # 2022-03-15: RasPiOS and Ubuntu install this regardless -- so rarely nec but just in case. + - parted # 2022-03-15: RasPiOS and Ubuntu install this regardless -- so rarely nec, but just in case. - cloud-guest-utils # 2022-03-15: For growpart command -- though RasPiOS currently doesn't need this, as raspi-config's do_expand_rootfs() instead uses fdisk. Ubuntu pre-installs cloud-guest-utils, for use with cloud-init. state: present @@ -14,7 +14,7 @@ - { src: 'iiab-expand-rootfs', dest: '/usr/sbin/', mode: '0755' } - { src: 'iiab-expand-rootfs.service', dest: '/etc/systemd/system/', mode: '0644' } -- name: Enable /etc/systemd/system/iiab-expand-rootfs.service +- name: Enable iiab-expand-rootfs.service systemd: name: iiab-expand-rootfs enabled: yes diff --git a/roles/1-prep/tasks/internal-wifi.yml b/roles/1-prep/tasks/internal-wifi.yml index 2751dfd13..62527a678 100644 --- a/roles/1-prep/tasks/internal-wifi.yml +++ b/roles/1-prep/tasks/internal-wifi.yml @@ -1,13 +1,14 @@ -- name: Look for any wireless devices present +- name: "Look for any WiFi devices present: ls -la /sys/class/net/*/phy80211 | cut -d/ -f5" shell: ls -la /sys/class/net/*/phy80211 | cut -d/ -f5 - register: has_wifi_device + register: wifi_devices ignore_errors: True changed_when: False -- name: Set internal_wifi, if found +- name: "Set internal_wifi: True, if output (from above) shows device(s) here: {{ wifi_devices.stdout_lines }}" set_fact: internal_wifi: True - when: has_wifi_device is defined and has_wifi_device.stdout | trim != "" + when: wifi_devices is defined and wifi_devices.stdout_lines | length > 0 + # when: wifi_devices is defined and wifi_devices.stdout | trim != "" # 2021-07-27 explanation from @jvonau: The 3 BELOW (iw, rfkill, wireless-tools) # are provided by RasPiOS. Ubuntu|Debian on the other hand are hit or miss: @@ -15,7 +16,7 @@ # these present at all, but are needed to be installed if you want to take full # advantage of WiFi on Ubuntu and friends. -- name: 'Install packages: iw, rfkill, wireless-tools' +- name: Install packages {iw, rfkill, wireless-tools} if internal_wifi ({{ internal_wifi }}) is defined package: name: - iw # 2021-07-27: RasPiOS installs this regardless -- configure Linux wireless devices -- hard dependence for ap0 creation, SEE https://github.com/iiab/iiab/blob/master/roles/network/templates/hostapd/iiab-clone-wifi.service.j2