2022-06-30 00:01:03 +00:00
# Similar code block in roles/vnstat/tasks/install.yml
2022-06-29 22:37:13 +00:00
- name : Do we have a gateway? If 'ip route' specifies a default route, Ansible parses details here...
debug :
var : ansible_default_ipv4
- name : "If above ansible_default_ipv4.gateway is defined, set WAN candidate 'discovered_wan_iface: {{ ansible_default_ipv4.alias }}' -- using ansible_default_ipv4.alias"
set_fact :
discovered_wan_iface : "{{ ansible_default_ipv4.alias }}"
when : ansible_default_ipv4.gateway is defined
2020-04-06 10:19:16 +00:00
# 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
2018-10-15 10:41:58 +00:00
shell : grep IIAB_WAN_DEVICE {{ iiab_env_file }} | awk -F "=" '{print $2}'
2020-04-06 10:19:16 +00:00
when : iiab_stage|int == 9
2017-10-15 20:08:08 +00:00
register : prior_gw
2017-05-27 18:09:50 +00:00
2020-04-06 10:19:16 +00:00
- name : Setting device_gw, prior_gw_device
2017-05-27 18:09:50 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
device_gw : "{{ prior_gw.stdout }}"
2020-04-06 10:19:16 +00:00
prior_gw_device : "{{ prior_gw.stdout }}"
when : prior_gw.stdout is defined and prior_gw.stdout != ""
2017-09-19 07:46:37 +00:00
2020-04-06 10:19:16 +00:00
- name : Setting WAN, device_gw if detected
2017-05-27 18:09:50 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
iiab_wan_iface : "{{ discovered_wan_iface }}"
device_gw : "{{ discovered_wan_iface }}"
2017-10-31 14:49:56 +00:00
when : ansible_default_ipv4.gateway is defined
2017-05-27 18:09:50 +00:00
2020-04-04 10:52:35 +00:00
- name : Figure out netplan file name
shell : ls /etc/netplan
register : netplan
ignore_errors : True # pre 17.10 doesn't use netplan
when : is_ubuntu
2017-05-27 18:09:50 +00:00
2017-11-10 16:39:20 +00:00
- name : Setting dhcpcd_test results
2017-09-24 20:09:43 +00:00
set_fact :
2017-11-23 06:24:44 +00:00
dhcpcd_result : "{{ ansible_local.local_facts.dhcpcd }}"
- name : Setting systemd_networkd results
set_fact :
systemd_networkd_active : True
when : 'ansible_local.local_facts.systemd_networkd == "enabled"'
2018-05-20 16:34:02 +00:00
- name : Setting systemd_networkd-2 results
set_fact :
systemd_networkd_active : True
when : 'ansible_local.local_facts.systemd_networkd == "enabled-runtime"'
2017-11-23 06:24:44 +00:00
- name : Setting network_manager results
set_fact :
network_manager_active : True
when : 'ansible_local.local_facts.network_manager == "enabled"'
2017-09-24 20:09:43 +00:00
2017-11-10 16:39:20 +00:00
- name : Check /etc/network/interfaces for gateway
2017-09-24 20:09:43 +00:00
shell : grep {{ device_gw }} /etc/network/interfaces | wc -l
2020-10-16 20:46:19 +00:00
when : is_debuntu
2017-09-24 20:09:43 +00:00
register : wan_file
2017-11-10 16:39:20 +00:00
- name : Setting wan_in_interfaces
2017-09-24 20:09:43 +00:00
set_fact :
wan_in_interfaces : True
2019-07-07 03:59:12 +00:00
when : is_debuntu and (wan_file.stdout|int > 0)
2017-09-24 20:09:43 +00:00
2017-05-27 18:09:50 +00:00
# WIRELESS -- if any wireless is detected as gateway, it becomes WAN
- name : Look for any wireless interfaces
2017-09-11 16:14:13 +00:00
shell : "cat /proc/net/wireless | grep -v -e Inter -e face | awk -F: '{print $1}' "
2017-05-27 18:09:50 +00:00
register : wireless_list1
ignore_errors : True
changed_when : False
- name : Set the discovered wireless, if found
set_fact :
2018-10-08 21:58:38 +00:00
wifi1 : "{{ item|trim }}"
discovered_wireless_iface : "{{ item|trim }}"
2017-05-27 18:09:50 +00:00
when : item|trim != "" and item|trim != discovered_wan_iface
2017-10-19 06:33:02 +00:00
with_items :
2018-10-08 21:58:38 +00:00
- "{{ wireless_list1.stdout_lines }}"
2017-05-27 18:09:50 +00:00
# WIRELESS -- Sigh... Not all drivers update /proc/net/wireless correctly
2017-10-27 17:49:00 +00:00
- name : Look for any wireless interfaces (take 2)
2017-05-27 18:09:50 +00:00
shell : "ls -la /sys/class/net/*/phy80211 | awk -F / '{print $5}'"
register : wireless_list2
ignore_errors : True
changed_when : False
# Last device is used
2017-10-27 17:49:00 +00:00
- name : Set the discovered wireless, if found (take 2)
2017-05-27 18:09:50 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
wifi2 : "{{ item|trim }}"
discovered_wireless_iface : "{{ item|trim }}"
2020-04-06 10:19:16 +00:00
when : wireless_list2.stdout is defined and item|trim != "ap0"
2017-05-27 18:09:50 +00:00
with_items :
2018-10-08 21:58:38 +00:00
- "{{ wireless_list2.stdout_lines }}"
2017-11-18 17:41:57 +00:00
#item|trim != discovered_wan_iface
2017-05-27 18:09:50 +00:00
2017-10-27 17:24:19 +00:00
- name : Count WiFi ifaces
2020-04-03 08:53:46 +00:00
shell : "ls -la /sys/class/net/*/phy80211 | awk -F / '{print $5}' | grep -v -e ap0 | wc -l"
2017-05-27 18:09:50 +00:00
register : count_wifi_interfaces
2017-10-27 17:24:19 +00:00
- name : Remember number of WiFi devices
2017-05-27 18:09:50 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
num_wifi_interfaces : "{{ count_wifi_interfaces.stdout|int }}"
2017-05-27 18:09:50 +00:00
2022-05-19 03:48:54 +00:00
- name : Run 'iw list' to check for Access Point capability
#command: iw list | grep -v AP: | grep AP | wc -l # False positives 'EAP' etc
shell : iw list | grep '^[[:space:]]*\* AP$'
2021-12-17 10:10:31 +00:00
register : look_for_ap
when : discovered_wireless_iface != "none"
2022-05-19 03:48:54 +00:00
- name : Set can_be_ap if 'iw list' output contains suitable '* AP'
2021-12-17 10:10:31 +00:00
set_fact :
can_be_ap : True
2022-05-19 04:04:57 +00:00
when : look_for_ap.failed is defined and not look_for_ap.failed
2021-12-17 10:10:31 +00:00
2020-09-15 03:53:30 +00:00
- name : Detect wifi gateway active
shell : ip r | grep default | grep {{ discovered_wireless_iface }} | wc -l
register : wifi_gateway_found
when : discovered_wireless_iface != "none"
2020-10-09 12:30:18 +00:00
- name : Set has_wifi_gateway if WiFi has default gateway detected for {{ discovered_wireless_iface }}
2020-09-15 03:53:30 +00:00
set_fact :
has_wifi_gateway : True
when : discovered_wireless_iface != "none" and (wifi_gateway_found.stdout|int > 0)
2020-10-07 18:59:16 +00:00
- name : Detect secondary gateway active on all interfaces
2020-09-15 12:53:46 +00:00
shell : ip r | grep default | grep -v {{ discovered_wan_iface }} | awk '{print $5}'
register : second_gateway_found
2020-10-07 18:59:16 +00:00
changed_when : False
2020-09-15 12:53:46 +00:00
2020-10-07 18:59:16 +00:00
- name : Set exclude_devices if default gateway has been detected for {{ second_gateway_found.stdout }}
2020-09-15 12:53:46 +00:00
set_fact :
2020-10-09 12:30:18 +00:00
exclude_devices : "{{ second_gateway_found.stdout }}"
2020-10-07 18:59:16 +00:00
when : second_gateway_found.stdout != ""
2020-09-15 12:53:46 +00:00
2017-05-27 18:09:50 +00:00
# XO hack here ap_device would not be active therefore not set with
# wired as gw use ap_device to exclude eth0 from network calulations
2020-09-15 03:53:30 +00:00
#- name: XO laptop override 2 WiFi on LAN
# set_fact:
2020-09-15 12:34:50 +00:00
# exclude_devices: "-e eth0"
2020-09-15 03:53:30 +00:00
# when: iiab_wan_iface != "eth0" and discovered_wireless_iface != "none" and xo_model == "XO-1.5"
2017-05-27 18:09:50 +00:00
2020-04-04 08:15:14 +00:00
- name : Exclude reserved Network Adapter if defined - takes adapter name
2017-05-27 18:09:50 +00:00
set_fact :
2020-10-09 12:30:18 +00:00
exclude_devices : "{{ exclude_devices }} -e {{ reserved_device }}"
2020-04-04 08:15:14 +00:00
when : reserved_device is defined
2017-05-27 18:09:50 +00:00
- name : Count LAN ifaces
2020-10-09 12:30:18 +00:00
shell : ls /sys/class/net | grep -v {{ virtual_network_devices }} -e wwlan -e ppp -e {{ device_gw }} -e {{ exclude_devices }} | wc -l
2017-05-27 18:09:50 +00:00
register : num_lan_interfaces_result
2017-11-10 16:39:20 +00:00
- name : Calculate number of LAN interfaces including WiFi
2017-05-27 18:09:50 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
num_lan_interfaces : "{{ num_lan_interfaces_result.stdout|int }}"
2017-05-27 18:09:50 +00:00
2017-11-09 06:24:29 +00:00
# LAN - pick non WAN's
- name : Create list of LAN (non WAN) ifaces
2020-10-09 12:30:18 +00:00
shell : ls /sys/class/net | grep -v {{ virtual_network_devices }} -e wwlan -e ppp -e {{ device_gw }} -e {{ exclude_devices }}
2017-11-22 15:58:13 +00:00
when : num_lan_interfaces != "0"
2017-11-09 06:24:29 +00:00
register : lan_list_result
2017-05-27 18:09:50 +00:00
# If 2 interfaces found in gateway mode, with one wifi, declare other to be wan
#- name: In gateway mode with one wifi adapter, the other is WAN
# set_fact:
2017-06-09 23:25:56 +00:00
# iiab_wan_iface: "{{ discovered_lan_iface }}"
# iiab_lan_iface: "{{ discovered_wireless_iface }}"
2017-05-27 18:09:50 +00:00
# num_lan_interfaces: "1"
2017-06-09 23:25:56 +00:00
# when: iiab_lan_enabled and iiab_wan_enabled and num_lan_interfaces == "2" and discovered_wireless_iface != "none" and iiab_wan_iface == "none"
2017-05-27 18:09:50 +00:00
2017-11-01 12:45:55 +00:00
# Select an adapter that is not WAN and not wireless
2017-11-05 01:11:27 +00:00
# if there is more than one the last one wins
2017-12-28 19:26:56 +00:00
- name : Set discovered_wired_iface if present
2017-11-01 12:45:55 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
discovered_wired_iface : "{{ item|trim }}"
2017-11-22 15:58:13 +00:00
when : lan_list_result.stdout_lines is defined and item|trim != discovered_wireless_iface
2017-11-01 12:45:55 +00:00
with_items :
2018-10-08 21:58:38 +00:00
- "{{ lan_list_result.stdout_lines }}"
2017-11-01 12:45:55 +00:00
2020-04-13 07:15:14 +00:00
- name : Set iiab_wireless_lan_iface to {{ discovered_wireless_iface }} if not none
2017-05-27 18:09:50 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
iiab_wireless_lan_iface : "{{ discovered_wireless_iface }}"
2020-05-02 01:02:05 +00:00
when : discovered_wireless_iface != "none" and not wifi_up_down
2020-04-13 07:15:14 +00:00
- name : Set iiab_wireless_lan_iface to ap0 if WiFi device is present
set_fact :
iiab_wireless_lan_iface : ap0
when : discovered_wireless_iface != "none" and wifi_up_down
2017-11-01 12:45:55 +00:00
2017-12-28 19:26:56 +00:00
- name : Set iiab_wired_lan_iface if present
2017-11-01 12:45:55 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
iiab_wired_lan_iface : "{{ discovered_wired_iface }}"
2020-03-04 23:00:01 +00:00
when : discovered_wired_iface is defined and discovered_wired_iface != "none" and discovered_wired_iface != iiab_wan_iface and not is_raspbian
2017-05-27 18:09:50 +00:00
# use value only if present
2017-11-05 01:11:27 +00:00
- name : 2 or more devices on the LAN - use bridging
set_fact :
2018-10-08 21:58:38 +00:00
iiab_lan_iface : br0
2020-03-04 23:00:01 +00:00
when : num_lan_interfaces|int >= 2
2017-11-05 01:11:27 +00:00
2020-03-04 23:00:01 +00:00
- name : For Debian, always use bridging
2017-11-01 12:45:55 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
iiab_lan_iface : br0
2020-03-04 23:00:01 +00:00
when : num_lan_interfaces|int >= 1 and is_debuntu
2017-11-01 12:45:55 +00:00
2020-03-04 23:00:01 +00:00
- name : WiFi is on the LAN - use bridging
2017-05-27 18:09:50 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
iiab_lan_iface : br0
2017-11-05 16:59:57 +00:00
when : iiab_wireless_lan_iface is defined and not nobridge is defined
2017-05-27 18:09:50 +00:00
2017-11-01 20:43:19 +00:00
- name : Setting wired LAN as only interface - RPi
set_fact :
2018-10-08 21:58:38 +00:00
iiab_lan_iface : "{{ iiab_wired_lan_iface }}"
2017-11-05 16:59:57 +00:00
when : iiab_wired_lan_iface is defined and nobridge is defined
2017-05-27 18:09:50 +00:00
2017-11-01 20:43:19 +00:00
- name : Setting wireless LAN as only interface - RPi
set_fact :
2018-10-08 21:58:38 +00:00
iiab_lan_iface : "{{ iiab_wireless_lan_iface }}"
2017-11-05 16:59:57 +00:00
when : iiab_wireless_lan_iface is defined and nobridge is defined
2017-05-27 18:09:50 +00:00
2017-11-10 16:39:20 +00:00
- name : In VM disable LAN - needs local_vars entry to activate
2017-05-27 18:09:50 +00:00
set_fact :
2018-10-08 21:58:38 +00:00
iiab_lan_iface : none
no_net_restart : True
2017-10-31 22:30:55 +00:00
when : is_VM is defined
2017-05-27 18:09:50 +00:00
# OK try old gw this is a best guess based on what's in
2017-06-28 02:53:13 +00:00
# /etc/sysconfig/iiab_wan_device's last state intended to
2017-05-27 18:09:50 +00:00
# provide a seed value to display in the GUI when no
# gateway is present but we had one.
- name : Has old gateway and no discovered gateway setting WAN
set_fact :
gui_wan_iface : "{{ device_gw }}"
when : user_wan_iface == "auto" and device_gw != "none" and discovered_wan_iface == "none"
2018-10-15 11:01:09 +00:00
- name : Add 'detected_network' variable values to {{ iiab_ini_file }}
2018-10-08 21:58:38 +00:00
ini_file :
2018-10-15 08:54:01 +00:00
dest : "{{ iiab_ini_file }}"
2018-10-08 21:58:38 +00:00
section : detected_network
option : "{{ item.option }}"
2020-01-12 02:41:37 +00:00
value : "{{ item.value | string }}"
2017-05-27 18:09:50 +00:00
with_items :
2022-01-07 10:29:54 +00:00
- option : has_ifcfg_gw
value : "{{ has_ifcfg_gw }}"
- option : prior_gateway_device
value : "{{ prior_gw_device }}"
- option : dhcpcd_result
value : "{{ dhcpcd_result }}"
- option : network_manager_active
value : "{{ network_manager_active }}"
- option : systemd_networkd_active
value : "{{ systemd_networkd_active }}"
- option : wan_in_interfaces
value : "{{ wan_in_interfaces }}"
- option : wireless_list_1(wifi1)
value : "{{ wifi1 }}"
- option : wireless_list_2(wifi2)
value : "{{ wifi2 }}"
- option : num_wifi_interfaces
value : "{{ num_wifi_interfaces }}"
- option : discovered_wireless_iface
value : "{{ discovered_wireless_iface }}"
- option : discovered_wired_iface
value : "{{ discovered_wired_iface }}"
- option : 'exclude_devices'
value : "{{ exclude_devices }}"
- option : num_lan_interfaces
value : "{{ num_lan_interfaces }}"
- option : gui_static_wan
value : "{{ gui_static_wan }}"
- option : iiab_lan_iface
value : "{{ iiab_lan_iface }}"
- option : iiab_wan_iface
value : "{{ iiab_wan_iface }}"
2021-12-17 10:10:31 +00:00
- option : can_be_ap
value : "{{ can_be_ap }}"
2020-04-06 10:19:16 +00:00
# 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