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/computed_network.yml
2021-04-12 10:45:31 -05:00

171 lines
6.6 KiB
YAML

# just lie about active gateway present on XOs to suppress ifcfg-WAN
# auto-creation/moving with XOs using NM/system-connections/ via keyfile.
# ifcfg-rh acts on /etc/sys*/net*/ifcfg-* where we search for devices.
- name: Setting XO has WiFi gateway
set_fact:
user_wan_iface: "{{ discovered_wan_iface }}"
when: not (discovered_wan_iface == "none") and not (xo_model == "none") and has_ifcfg_gw == "none"
- name: XO laptop wants USB WiFi interface as AP mode
set_fact:
iiab_wireless_lan_iface: "{{ discovered_lan_iface }}"
when: num_wifi_interfaces >= "2" and not (xo_model == "none") and not (discovered_wan_iface == "none") and discovered_wireless_iface == "eth0"
# static backout suppy new template file
- name: gui-static-wan
set_fact:
wan_ip: dhcp
gui_static_wan_ip: undefined
when: not (gui_static_wan_ip == "unset") and not gui_static_wan
- name: Undo gui-static-wan by requesting new template file
set_fact:
has_WAN: False
when: not (gui_static_wan_ip == "unset") and not gui_static_wan
# figure out more than one interfaces to detect.
- name: Using GUI_STATIC info
set_fact:
has_WAN: False
has_ifcfg_gw: "none"
wan_ip: "{{ gui_static_wan_ip }}"
wan_netmask: "{{ gui_static_wan_netmask }}"
wan_gateway: "{{ gui_static_wan_gateway }}"
wan_nameserver: "{{ gui_static_wan_nameserver }}"
when: gui_static_wan or not (user_wan_iface == "auto")
# we need to have an interface name for ifcfg-WAN to be able to change gateway
# the DEVICE from the gui. Thanks to George for proving my point about knowing
# what device to switch to.
#- name: Using GUI_WAN info
# set_fact:
# user_wan_iface: "{{ gui_wan_iface }}"
# when: gui_wan_iface != "unset" and gui_desired_network_role is defined and gui_desired_network_role != "LanController"
# should make the GUI buttons the last call
- name: Checking iiab_wan_enabled
set_fact:
user_wan_iface: "none"
when: not iiab_wan_enabled
# gui wants LanController
# the change over might be a little bumpy ATM.
- name: Setting GUI wants 'LanController'
set_fact:
device_gw: "none"
user_wan_iface: "none"
iiab_gateway_enabled: "False"
when: gui_desired_network_role is defined and gui_desired_network_role == "LanController"
# 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: <device> 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 }}"
when: not (discovered_wan_iface == "none") and num_lan_interfaces == "0" and gui_desired_network_role is defined and gui_desired_network_role == "LanController"
# override with user_wan_iface setting if no longer in auto
- name: Setting user WAN fact
set_fact:
iiab_wan_iface: "{{ user_wan_iface }}"
when: not (user_wan_iface == "auto")
# user disabled interface - overriding all other entries
- name: Checking iiab_lan_enabled
set_fact:
user_lan_iface: "none"
when: not iiab_lan_enabled
# gui wants Appliance Note: could of used iiab_lan_enabled false
- name: Setting GUI wants 'Appliance'
set_fact:
user_lan_iface: "none"
iiab_gateway_enabled: "False"
when: gui_desired_network_role is defined and gui_desired_network_role == "Appliance"
# gui wants Gateway
- name: Setting GUI wants and has active 'Gateway'
set_fact:
user_lan_iface: "auto"
user_wan_iface: "{{ iiab_wan_iface }}"
when: gui_desired_network_role is defined and gui_desired_network_role == "Gateway" and not (iiab_wan_iface == "none")
# make it so number 2 vars should use user_wan_iface but we can cover a single
# wired if dhcp fails the interface should revert to LAN, static address should
# stick around but testing gateway response is not performed.
#- name: User wants single wired interface as static or dhcp gateway
# set_fact:
# user_wan_iface: "{{ discovered_wan_iface }}" # Jan 2018: Holt discovered_lan_iface was UNDEFINED on WiFi-installed
# # RPi (when re-running ./iiab-network) so "discovered_wan_iface" is a
# # workaround -- please see https://github.com/iiab/iiab/pull/649
# # This workaround can and should evolve as IIAB 6.5 matures!
# when: num_lan_interfaces == "1" and user_lan_iface == "auto" and user_wan_iface == "auto"
- name: Use old gateway device info if not detected and using static ip
set_fact:
iiab_wan_iface: "{{ device_gw }}"
when: not (wan_ip == "dhcp") and iiab_wan_iface == "none"
- name: No LAN configured - 'Appliance' mode
set_fact:
iiab_network_mode: "Appliance"
when: iiab_lan_iface == "none"
- name: LAN configured - 'LanController' mode
set_fact:
iiab_network_mode: "LanController"
when: not (iiab_lan_iface == "none") and iiab_wan_iface == "none"
- name: LAN configured - 'Gateway' mode
set_fact:
iiab_network_mode: "Gateway"
when: (not (iiab_lan_iface == "none") and not (iiab_wan_iface == "none"))
# override with user_lan_iface setting if no longer in auto
- name: Setting user LAN fact
set_fact:
iiab_lan_iface: "{{ user_lan_iface }}"
when: not (user_lan_iface == "auto")
- name: Record IIAB_WAN_DEVICE={{ iiab_wan_iface }} to {{ iiab_env_file }}
lineinfile:
path: "{{ iiab_env_file }}"
regexp: '^IIAB_WAN_DEVICE=*'
line: 'IIAB_WAN_DEVICE={{ iiab_wan_iface }}'
- name: Record IIAB_LAN_DEVICE={{ iiab_lan_iface }} to {{ iiab_env_file }}
lineinfile:
path: "{{ iiab_env_file }}"
regexp: '^IIAB_LAN_DEVICE=*'
line: 'IIAB_LAN_DEVICE={{ iiab_lan_iface }}'
state: present
- name: Record 'IIAB_GATEWAY_ENABLED={{ iiab_gateway_enabled }}' in {{ iiab_env_file }}
lineinfile:
path: "{{ iiab_env_file }}"
regexp: '^IIAB_GATEWAY_ENABLED=*'
line: 'IIAB_GATEWAY_ENABLED={{ iiab_gateway_enabled }}'
state: present
- name: Add 'computed_network' variable values to {{ iiab_ini_file }}
ini_file:
dest: "{{ iiab_ini_file }}"
section: computed_network
option: "{{ item.option }}"
value: "{{ item.value | string }}"
with_items:
- option: iiab_wan_enabled
value: "{{ iiab_wan_enabled }}"
- option: user_wan_iface
value: "{{ user_wan_iface }}"
- option: iiab_wan_iface
value: "{{ iiab_wan_iface }}"
- option: iiab_lan_enabled
value: "{{ iiab_lan_enabled }}"
- option: user_lan_iface
value: "{{ user_lan_iface }}"
- option: iiab_lan_iface
value: "{{ iiab_lan_iface }}"
- option: iiab_network_mode
value: "{{ iiab_network_mode }}"