1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 19:52:06 +00:00
iiab/roles/network/tasks/detected_network.yml

224 lines
7.9 KiB
YAML
Raw Normal View History

- name: iiab_wan_device
shell: grep IIAB_WAN_DEVICE /etc/iiab/iiab.env | awk -F "=" '{print $2}'
when: iiab_stage|int > 4
register: prior_gw
2017-05-27 18:09:50 +00:00
- name: Checking for old device gateway interface for device test
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 != ""
2017-09-19 07:46:37 +00:00
2017-10-27 17:49:00 +00:00
- name: Setting WAN if detected
2017-05-27 18:09:50 +00:00
set_fact:
iiab_wan_iface: "{{ discovered_wan_iface }}"
device_gw: "{{ discovered_wan_iface }}"
when: ansible_default_ipv4.gateway is defined
2017-05-27 18:09:50 +00:00
2017-11-10 16:39:20 +00:00
- name: Red Hat network detection (redhat)
include_tasks: detected_redhat.yml
2017-09-20 05:48:30 +00:00
when: is_redhat
2017-05-27 18:09:50 +00:00
2017-11-10 16:39:20 +00:00
- name: Setting dhcpcd_test results
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"'
- name: Setting network_manager results
set_fact:
network_manager_active: True
when: 'ansible_local.local_facts.network_manager == "enabled"'
2017-11-10 16:39:20 +00:00
- name: Check /etc/network/interfaces for gateway
shell: grep {{ device_gw }} /etc/network/interfaces | wc -l
when: is_debuntu
register: wan_file
2017-11-10 16:39:20 +00:00
- name: Setting wan_in_interfaces
set_fact:
wan_in_interfaces: True
2017-11-02 16:06:45 +00:00
when: is_debuntu and wan_file.stdout|int >= 0
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
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:
wifi1: "{{ item|trim }}"
discovered_wireless_iface: "{{ item|trim }}"
when: item|trim != "" and item|trim != discovered_wan_iface
with_items:
2017-05-27 18:09:50 +00:00
- "{{ wireless_list1.stdout_lines }}"
# 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:
wifi2: "{{ item|trim }}"
discovered_wireless_iface: "{{ item|trim }}"
2017-11-18 17:41:57 +00:00
when: wireless_list2.stdout is defined
2017-05-27 18:09:50 +00:00
with_items:
- "{{ 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
2017-05-27 18:09:50 +00:00
shell: "ls -la /sys/class/net/*/phy80211 | awk -F / '{print $5}' | wc -l"
register: count_wifi_interfaces
2017-11-01 12:45:55 +00:00
# facts are apparently all stored as text, so do text comparisons from here on
2017-10-27 17:24:19 +00:00
- name: Remember number of WiFi devices
2017-05-27 18:09:50 +00:00
set_fact:
num_wifi_interfaces: "{{ count_wifi_interfaces.stdout|int }}"
# 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
2017-10-27 17:24:19 +00:00
- name: XO laptop override 2 WiFi on LAN
2017-05-27 18:09:50 +00:00
set_fact:
ap_device: "eth0"
when: iiab_wan_iface != "eth0" and discovered_wireless_iface != "none" and xo_model == "XO-1.5"
2017-05-27 18:09:50 +00:00
- name: Exclude reserved WiFi adapter if defined - takes adapter name
2017-05-27 18:09:50 +00:00
set_fact:
ap_device: "{{ reserved_wifi }}"
when: reserved_wifi is defined and discovered_wireless_iface != iiab_wan_iface and num_wifi_interfaces >= "2"
2017-05-27 18:09:50 +00:00
- name: Count LAN ifaces
shell: ls /sys/class/net | grep -v -e wwlan -e ppp -e lo -e br0 -e tun -e {{ device_gw }} -e {{ ap_device }} | wc -l
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:
num_lan_interfaces: "{{ num_lan_interfaces_result.stdout|int }}"
# LAN - pick non WAN's
- name: Create list of LAN (non WAN) ifaces
shell: ls /sys/class/net | grep -v -e wwlan -e ppp -e lo -e br0 -e tun -e {{ device_gw }} -e {{ ap_device }}
when: num_lan_interfaces != "0"
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:
# iiab_wan_iface: "{{ discovered_lan_iface }}"
# iiab_lan_iface: "{{ discovered_wireless_iface }}"
2017-05-27 18:09:50 +00:00
# num_lan_interfaces: "1"
# 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
- name: Set discovered_wired_iface if present
2017-11-01 12:45:55 +00:00
set_fact:
discovered_wired_iface: "{{ item|trim }}"
when: lan_list_result.stdout_lines is defined and item|trim != discovered_wireless_iface
2017-11-01 12:45:55 +00:00
with_items:
- "{{ lan_list_result.stdout_lines }}"
- name: Set iiab_wireless_lan_iface if present
2017-05-27 18:09:50 +00:00
set_fact:
iiab_wireless_lan_iface: "{{ discovered_wireless_iface }}"
2017-11-01 12:45:55 +00:00
when: discovered_wireless_iface is defined and discovered_wireless_iface != "none" and discovered_wireless_iface != iiab_wan_iface
- name: Set iiab_wired_lan_iface if present
2017-11-01 12:45:55 +00:00
set_fact:
iiab_wired_lan_iface: "{{ discovered_wired_iface }}"
when: discovered_wired_iface is defined and discovered_wired_iface != "none" and discovered_wired_iface != iiab_wan_iface
2017-05-27 18:09:50 +00:00
#unused
2017-09-20 05:48:30 +00:00
#- name: Get a list of ifcfg files to delete
# moved to detected_redhat
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:
iiab_lan_iface: br0
2017-11-09 18:21:57 +00:00
when: num_lan_interfaces|int >= 2 and not is_rpi
2017-11-05 01:11:27 +00:00
2017-11-01 20:43:19 +00:00
- name: For Debian, always use bridging - except RPi
2017-11-01 12:45:55 +00:00
set_fact:
2017-11-01 20:43:19 +00:00
iiab_lan_iface: br0
2017-11-09 18:21:57 +00:00
when: num_lan_interfaces|int >= 1 and is_debuntu and not is_rpi
2017-11-01 12:45:55 +00:00
2017-11-01 20:43:19 +00:00
- name: WiFi is on the LAN - use bridging - except RPi
2017-05-27 18:09:50 +00:00
set_fact:
2017-11-01 20:43:19 +00:00
iiab_lan_iface: br0
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:
iiab_lan_iface: "{{ iiab_wired_lan_iface }}"
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:
iiab_lan_iface: "{{ iiab_wireless_lan_iface }}"
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:
2017-11-01 12:45:55 +00:00
iiab_lan_iface: none
2017-11-01 23:15:28 +00:00
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
# /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"
- name: Add location section to config file
ini_file: dest='{{ iiab_config_file }}'
2017-10-16 01:22:22 +00:00
section=detected_network
2017-05-27 18:09:50 +00:00
option='{{ item.option }}'
value='{{ item.value }}'
with_items:
- option: 'has_ifcfg_gw'
2017-05-27 18:09:50 +00:00
value: '{{ has_ifcfg_gw }}'
- option: 'prior_gateway_(device_gw2)'
2017-05-27 18:09:50 +00:00
value: '{{ device_gw2 }}'
2017-11-05 01:11:27 +00:00
- option: 'dhcpcd_result'
value: '{{ dhcpcd_result }}'
2017-11-23 06:24:44 +00:00
- option: 'network_manager_active'
value: '{{ network_manager_active }}'
- option: 'systemd_networkd_active'
value: '{{ systemd_networkd_active }}'
2017-11-05 01:11:27 +00:00
- option: 'wan_in_interfaces'
value: '{{ wan_in_interfaces }}'
- option: 'wireless_list_1(wifi1)'
2017-05-27 18:09:50 +00:00
value: '{{ wifi1 }}'
- option: 'wireless_list_2(wifi2)'
2017-05-27 18:09:50 +00:00
value: '{{ wifi2 }}'
- option: 'num_wifi_interfaces'
value: '{{ num_wifi_interfaces }}'
- option: 'discovered_wireless_iface'
value: '{{ discovered_wireless_iface }}'
2017-11-01 12:45:55 +00:00
- option: 'discovered_wired_iface'
value: '{{ discovered_wired_iface }}'
2017-11-05 01:11:27 +00:00
# - option: 'iiab_wireless_lan_iface'
# value: '{{ iiab_wireless_lan_iface }}'
- option: 'num_lan_interfaces'
value: '{{ num_lan_interfaces }}'
- option: 'gui_static_wan'
2017-05-27 18:09:50 +00:00
value: '{{ gui_static_wan }}'
2017-11-02 16:06:45 +00:00
- option: 'iiab_lan_iface'
2017-11-01 12:45:55 +00:00
value: '{{ iiab_lan_iface }}'
2017-11-05 01:11:27 +00:00
- option: 'iiab_wan_iface'
value: '{{ iiab_wan_iface }}'