From 52252044f100b9aaa7df7e84e225c9c36f8bf9c4 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 15 Mar 2022 12:47:39 -0500 Subject: [PATCH] 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