From 1d4e427fa96d79900e2f14596777dd4a44d084aa Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 6 Apr 2020 05:19:16 -0500 Subject: [PATCH] softcode exclude devices, move tests and turn into hard failures, record wifi after channel detection, prior_gateway_device, fix ap0 exclude --- roles/network/defaults/main.yml | 3 +- roles/network/tasks/computed_network.yml | 49 ++--------------------- roles/network/tasks/computed_services.yml | 8 ++++ roles/network/tasks/detected_network.yml | 46 ++++++++++++++------- roles/network/tasks/main.yml | 2 +- 5 files changed, 46 insertions(+), 62 deletions(-) diff --git a/roles/network/defaults/main.yml b/roles/network/defaults/main.yml index 87296ede1..867ab89f6 100644 --- a/roles/network/defaults/main.yml +++ b/roles/network/defaults/main.yml @@ -62,13 +62,14 @@ strict_networking: False iiab_demo_mode: False gui_static_wan: False wan_cidr: +virtual_network_devices: "-e ap0 -e lo -e br0 -e tun -e br- -e docker -e bridge0 -e veth" # Set defaults for discovery process as strings wifi1: "not found-1" wifi2: "not found-2" exclude_device: "none" device_gw: "none" -device_gw2: "" +prior_gw_device: "" iiab_wan_iface: "none" iiab_lan_iface: "none" diff --git a/roles/network/tasks/computed_network.yml b/roles/network/tasks/computed_network.yml index fb27dc7b5..08540b94e 100644 --- a/roles/network/tasks/computed_network.yml +++ b/roles/network/tasks/computed_network.yml @@ -6,20 +6,6 @@ user_wan_iface: "{{ discovered_wan_iface }}" when: not (discovered_wan_iface == "none") and not (xo_model == "none") and has_ifcfg_gw == "none" -#- name: Checking for NetworkManager-config-server -# shell: rpm -qa | grep NetworkManager-config-server | wc -l -# register: strict_networking_check - -#- name: Found Checking for NetworkManager-config-server -# set_fact: -# strict_networking: True -# when: strict_networking_check == "1" - -#- name: Use restricted network features -# set_fact: -# iiab_demo_mode: True -# when: teamviewer_install and not strict_networking - - name: XO laptop wants USB WiFi interface as AP mode set_fact: iiab_wireless_lan_iface: "{{ discovered_lan_iface }}" @@ -62,7 +48,7 @@ user_wan_iface: "none" when: not iiab_wan_enabled -# gui wants LanController # keeps ifcfg-WAN but onboot=no +# gui wants LanController # the change over might be a little bumpy ATM. - name: Setting GUI wants 'LanController' set_fact: @@ -71,10 +57,9 @@ iiab_gateway_enabled: "False" when: gui_desired_network_role is defined and gui_desired_network_role == "LanController" -# device_gw is used with the LAN detection and LAN's ifcfg file deletion. -# single interface vars/ users would need to set iiab_wan_enabled False as above, to disable the WAN -# and set user_lan_iface = to suppress the auto detection for the same effect. - +# discovered_wan_iface is used with the LAN detection, single interface vars/ users would +# need to set iiab_wan_enabled False as above, to disable the WAN and set +# user_lan_iface: to suppress the auto detection for the same effect. - name: Setting user_lan_iface for 'LanController' for single interface set_fact: user_lan_iface: "{{ discovered_wan_iface }}" @@ -143,24 +128,6 @@ iiab_lan_iface: "{{ user_lan_iface }}" when: not (user_lan_iface == "auto") -# so this works -- name: Interface count - shell: ls /sys/class/net | grep -v -e lo -e bridge0 -e veth -e "br-*" -e docker| wc | awk '{print $1}' - register: adapter_count - -# well if there ever was a point to tell the user things are FUBAR this is it. -- name: We're hosed no work interfaces - set_fact: - iiab_network_mode: "No_network_found" - when: adapter_count.stdout|int == 0 - -# well if there ever was a point to tell the user things are FUBAR this is it. -- name: I'm not guessing declare gateway please - set_fact: - iiab_network_mode: "Undetectable_use_local_vars" - iiab_wan_iface: "none" - when: adapter_count.stdout|int >= 5 and device_gw == "none" and gui_wan_iface == "unset" and gui_static_wan is defined - - name: Record IIAB_WAN_DEVICE to {{ iiab_env_file }} lineinfile: path: "{{ iiab_env_file }}" @@ -197,11 +164,3 @@ value: "{{ iiab_lan_iface }}" - option: iiab_network_mode value: "{{ iiab_network_mode }}" - - option: hostapd_enabled - value: "{{ hostapd_enabled }}" - - option: host_ssid - value: "{{ host_ssid }}" - - option: host_wifi_mode - value: "{{ host_wifi_mode }}" - - option: host_channel - value: "{{ host_channel }}" diff --git a/roles/network/tasks/computed_services.yml b/roles/network/tasks/computed_services.yml index 72fdd951c..1c4ee95ba 100644 --- a/roles/network/tasks/computed_services.yml +++ b/roles/network/tasks/computed_services.yml @@ -74,3 +74,11 @@ value: "{{ dnsmasq_enabled }}" - option: no_net_restart value: "{{ no_net_restart }}" + - option: hostapd_enabled + value: "{{ hostapd_enabled }}" + - option: host_ssid + value: "{{ host_ssid }}" + - option: host_wifi_mode + value: "{{ host_wifi_mode }}" + - option: host_channel + value: "{{ host_channel }}" diff --git a/roles/network/tasks/detected_network.yml b/roles/network/tasks/detected_network.yml index 95cdbeef3..e2dc13e32 100644 --- a/roles/network/tasks/detected_network.yml +++ b/roles/network/tasks/detected_network.yml @@ -1,15 +1,26 @@ -- name: iiab_wan_device - shell: grep IIAB_WAN_DEVICE {{ iiab_env_file }} | awk -F "=" '{print $2}' - when: iiab_stage|int > 4 - register: prior_gw +# so this works +- name: Interface count + shell: ls /sys/class/net | grep -v {{ virtual_network_devices }} | wc | awk '{print $1}' + register: adapter_count + +# well if there ever was a point to tell the user things are FUBAR this is it. +- name: We're hosed no work interfaces + fail: # FORCE IT RED THIS ONCE! + msg: "No_network_found" + when: adapter_count.stdout|int == 0 - name: Checking for old device gateway interface for device test + shell: grep IIAB_WAN_DEVICE {{ iiab_env_file }} | awk -F "=" '{print $2}' + when: iiab_stage|int == 9 + register: prior_gw + +- name: Setting device_gw, prior_gw_device set_fact: device_gw: "{{ prior_gw.stdout }}" - device_gw2: "{{ prior_gw.stdout }}" - when: iiab_stage|int > 4 and prior_gw is defined and prior_gw.stdout != "" + prior_gw_device: "{{ prior_gw.stdout }}" + when: prior_gw.stdout is defined and prior_gw.stdout != "" -- name: Setting WAN if detected +- name: Setting WAN, device_gw if detected set_fact: iiab_wan_iface: "{{ discovered_wan_iface }}" device_gw: "{{ discovered_wan_iface }}" @@ -77,7 +88,7 @@ set_fact: wifi2: "{{ item|trim }}" discovered_wireless_iface: "{{ item|trim }}" - when: wireless_list2.stdout is defined and not wireless_list2.stdout == "ap0" + when: wireless_list2.stdout is defined and item|trim != "ap0" with_items: - "{{ wireless_list2.stdout_lines }}" #item|trim != discovered_wan_iface @@ -86,7 +97,6 @@ shell: "ls -la /sys/class/net/*/phy80211 | awk -F / '{print $5}' | grep -v -e ap0 | wc -l" register: count_wifi_interfaces -# facts are apparently all stored as text, so do text comparisons from here on - name: Remember number of WiFi devices set_fact: num_wifi_interfaces: "{{ count_wifi_interfaces.stdout|int }}" @@ -96,17 +106,16 @@ - name: XO laptop override 2 WiFi on LAN set_fact: - ap_device: "eth0" + exclude_device: "eth0" when: iiab_wan_iface != "eth0" and discovered_wireless_iface != "none" and xo_model == "XO-1.5" - name: Exclude reserved Network Adapter if defined - takes adapter name set_fact: exclude_device: "{{ reserved_device }}" -# when: reserved_device is defined and discovered_wireless_iface != iiab_wan_iface and num_wifi_interfaces >= "2" when: reserved_device is defined - name: Count LAN ifaces - shell: ls /sys/class/net | grep -v -e ap0 -e wwlan -e ppp -e lo -e br0 -e tun -e br- -e docker -e bridge0 -e veth -e {{ device_gw }} -e {{ exclude_device }} | wc -l + shell: ls /sys/class/net | grep -v {{ virtual_network_devices }} -e wwlan -e ppp -e {{ device_gw }} -e {{ exclude_device }} | wc -l register: num_lan_interfaces_result - name: Calculate number of LAN interfaces including WiFi @@ -115,7 +124,7 @@ # LAN - pick non WAN's - name: Create list of LAN (non WAN) ifaces - shell: ls /sys/class/net | grep -v -e ap0 -e wwlan -e ppp -e lo -e br0 -e tun -e br- -e docker -e bridge0 -e veth -e {{ device_gw }} -e {{ exclude_device }} + shell: ls /sys/class/net | grep -v {{ virtual_network_devices }} -e wwlan -e ppp -e {{ device_gw }} -e {{ exclude_device }} when: num_lan_interfaces != "0" register: lan_list_result @@ -196,8 +205,8 @@ with_items: - option: has_ifcfg_gw value: "{{ has_ifcfg_gw }}" - - option: prior_gateway_(device_gw2) - value: "{{ device_gw2 }}" + - option: prior_gateway_device + value: "{{ prior_gw_device }}" - option: dhcpcd_result value: "{{ dhcpcd_result }}" - option: network_manager_active @@ -226,3 +235,10 @@ value: "{{ iiab_lan_iface }}" - option: iiab_wan_iface value: "{{ iiab_wan_iface }}" + +# well if there ever was a point to tell the user things are FUBAR this is it. +# limit 2 network adapters wifi wired +- name: I'm not guessing declare gateway please + fail: # FORCE IT RED THIS ONCE! + msg: "Undetectable gateway or prior gateway for use with static network addressing from admin-console use local_vars to declare user_wan_iface" + when: adapter_count.stdout|int >=3 and gui_wan_iface == "unset" and gui_static_wan diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 486532cae..dcff50019 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -51,9 +51,9 @@ #### Start services - include_tasks: avahi.yml +- include_tasks: hostapd.yml - include_tasks: computed_services.yml - include_tasks: enable_services.yml -- include_tasks: hostapd.yml #### End services