2017-06-09 23:25:56 +00:00
|
|
|
# The preferred method of disabling the LAN would be to set iiab_lan_enabled:
|
2017-05-27 18:09:50 +00:00
|
|
|
# False before getting here but we are here...
|
2017-10-19 06:33:02 +00:00
|
|
|
# Well if we got here something changed with the gateway and ifcfg-WAN maybe
|
|
|
|
# no longer accurate. Note if DEVICE= is any ifcfg files the listed DEVICE
|
|
|
|
# becomes bound to the NAME in the ifcfg file. With the LAN files out of the
|
2017-05-27 18:09:50 +00:00
|
|
|
# way we can try the interfaces one by one starting with device_gw.
|
|
|
|
|
|
|
|
# Setting up three way conditions with the results
|
|
|
|
# skipped|changed|failed
|
2017-10-19 06:33:02 +00:00
|
|
|
# failure results in blowing away the ifcfg-WAN so lets make sure...
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2017-10-19 06:33:02 +00:00
|
|
|
# We only got here by way of no detected gateway, lets see if we can pick-up
|
|
|
|
# transient change like cable issues.
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
- name: BAD DHCP defaults
|
|
|
|
set_fact:
|
|
|
|
dhcp_good: False
|
|
|
|
|
|
|
|
# don't shoot ourselves in the foot....
|
2018-10-08 22:34:16 +00:00
|
|
|
- name: Disable dhcpd server just because
|
|
|
|
service:
|
|
|
|
name: dhcpd
|
|
|
|
state: stopped
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
### clear all connections first
|
2017-10-19 06:33:02 +00:00
|
|
|
# We should have the LAN torndown at this point.
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
- name: No ifcfg-WAN known
|
2018-10-08 22:34:16 +00:00
|
|
|
debug:
|
|
|
|
msg: "NO WAN known"
|
2017-05-27 18:09:50 +00:00
|
|
|
when: not has_WAN
|
|
|
|
|
2017-10-27 16:08:35 +00:00
|
|
|
- name: Finding connection name for WiFi AP gateway first
|
2017-05-27 18:09:50 +00:00
|
|
|
shell: egrep -rn NAME /etc/sysconfig/network-scripts/{{ has_wifi_gw }} | gawk -F '=' '{print $2}'
|
|
|
|
register: ap_name
|
|
|
|
when: has_wifi_gw != "none" and has_ifcfg_gw != "none"
|
|
|
|
|
2017-10-27 16:08:35 +00:00
|
|
|
- name: Trying WiFi first
|
2017-05-27 18:09:50 +00:00
|
|
|
shell: nmcli conn up id {{ ap_name.stdout }}
|
2017-10-19 06:33:02 +00:00
|
|
|
register: try_wifi
|
2017-05-27 18:09:50 +00:00
|
|
|
ignore_errors: yes
|
|
|
|
when: ap_name is defined and ap_named.changed
|
|
|
|
|
|
|
|
- name: Checking for WiFi gateway
|
|
|
|
shell: sleep 5 | ip route | grep default | awk '{print $5}'
|
|
|
|
register: dhcp_wifi_results
|
|
|
|
when: try_wifi is defined and try_wifi.changed
|
|
|
|
|
|
|
|
# We have the DEVICE?
|
2017-10-27 17:55:24 +00:00
|
|
|
- name: Now setting iiab_wan_iface based on WiFi
|
2017-10-19 06:33:02 +00:00
|
|
|
set_fact:
|
2018-10-08 22:34:16 +00:00
|
|
|
iiab_wan_iface: "{{ dhcp_wifi_results.stdout }}"
|
|
|
|
dhcp_good: True
|
2017-05-27 18:09:50 +00:00
|
|
|
when: dhcp_wifi_results.stdout is defined and dhcp_wifi_results.stdout != ""
|
|
|
|
|
|
|
|
- name: Trying ifcfg-WAN second
|
2017-06-09 23:25:56 +00:00
|
|
|
shell: nmcli conn up id iiab-WAN
|
2017-05-27 18:09:50 +00:00
|
|
|
register: dhcp_WAN
|
|
|
|
ignore_errors: yes
|
|
|
|
when: has_WAN
|
|
|
|
|
|
|
|
- name: BAD ifcfg-WAN
|
2018-10-08 22:34:16 +00:00
|
|
|
debug:
|
|
|
|
msg: "BAD WAN"
|
2017-05-27 18:09:50 +00:00
|
|
|
when: dhcp_WAN is defined and dhcp_WAN|failed
|
|
|
|
|
|
|
|
- name: Delete ifcfg-WAN
|
|
|
|
shell: rm -f /etc/sysconfig/network-scripts/ifcfg-WAN
|
|
|
|
when: dhcp_WAN is defined and dhcp_WAN|failed and wan_ip == "dhcp"
|
|
|
|
|
|
|
|
- name: Setting no ifcfg-WAN
|
|
|
|
set_fact:
|
2018-10-08 22:34:16 +00:00
|
|
|
has_WAN: False
|
2017-05-27 18:09:50 +00:00
|
|
|
when: dhcp_WAN is defined and dhcp_WAN|failed and wan_ip == "dhcp"
|
|
|
|
|
2017-10-27 16:08:35 +00:00
|
|
|
- name: Interface list
|
2017-05-27 18:09:50 +00:00
|
|
|
shell: ls /sys/class/net | grep -v -e lo -e br -e tun
|
|
|
|
register: adapter_list
|
|
|
|
|
|
|
|
# wired devices with no wire plugged in fail here
|
|
|
|
- name: Not risking an active device dropping all devices
|
|
|
|
shell: nmcli d delete {{ item|trim }}
|
|
|
|
ignore_errors: True
|
2017-06-09 23:25:56 +00:00
|
|
|
when: item|trim != iiab_wireless_lan_iface and not dhcp_good and wan_ip == "dhcp"
|
2017-05-27 18:09:50 +00:00
|
|
|
with_items:
|
2018-10-08 22:34:16 +00:00
|
|
|
- "{{ adapter_list.stdout_lines }}"
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
# monitor-connection-files defaults to no with F21, F18-F20 defaults to yes
|
|
|
|
- name: Reloading nmcli for deleted files
|
|
|
|
shell: nmcli con reload
|
|
|
|
when: not installing and not no_NM_reload
|
|
|
|
|
|
|
|
# wired devices with no wire plugged in fail here
|
|
|
|
# discovered_wireless_iface might need work
|
|
|
|
- name: Try dhcp on all wired devices
|
|
|
|
shell: nmcli d connect {{ item|trim }}
|
|
|
|
ignore_errors: True
|
2017-06-09 23:25:56 +00:00
|
|
|
when: item|trim != discovered_wireless_iface and item|trim != iiab_wireless_lan_iface and not dhcp_good and wan_ip == "dhcp"
|
2017-05-27 18:09:50 +00:00
|
|
|
with_items:
|
2018-10-08 22:34:16 +00:00
|
|
|
- "{{ adapter_list.stdout_lines }}"
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
# This should be neat on a VM with 2 bridged interfaces.
|
|
|
|
- name: Checking for gateway
|
|
|
|
shell: sleep 5 | ip route | grep default | awk '{print $5}'
|
|
|
|
register: dhcp_1BY1_results
|
|
|
|
when: not has_WAN and not dhcp_good
|
|
|
|
|
|
|
|
# We have the DEVICE?
|
2017-06-09 23:25:56 +00:00
|
|
|
- name: Now setting iiab_wan_iface via nmcli
|
2017-10-19 06:33:02 +00:00
|
|
|
set_fact:
|
2018-10-08 22:34:16 +00:00
|
|
|
iiab_wan_iface: "{{ dhcp_1BY1_results.stdout }}"
|
|
|
|
dhcp_good: True
|
2017-05-27 18:09:50 +00:00
|
|
|
when: dhcp_1BY1_results.stdout is defined and dhcp_1BY1_results.stdout != "" and not has_WAN
|
|
|
|
|
|
|
|
- name: Find gateway config based on device
|
2017-06-09 23:25:56 +00:00
|
|
|
shell: egrep -rn "{{ iiab_wan_iface }}" /etc/sysconfig/network-scripts/ifcfg* | gawk -F ':' '{print $1}'
|
2017-05-27 18:09:50 +00:00
|
|
|
register: ifcfg_dhcp_device
|
|
|
|
ignore_errors: True
|
|
|
|
changed_when: False
|
|
|
|
when: dhcp_good
|
|
|
|
|
|
|
|
- name: Setting has ifcfg gw based on device if found
|
|
|
|
set_fact:
|
|
|
|
has_ifcfg_gw: "{{ item|trim }}"
|
|
|
|
when: dhcp_good and ifcfg_dhcp_device is defined and item|trim != ""
|
|
|
|
with_items:
|
2018-10-08 22:34:16 +00:00
|
|
|
- "{{ ifcfg_dhcp_device.stdout_lines }}"
|
2017-05-27 18:09:50 +00:00
|
|
|
ignore_errors: True
|
|
|
|
|
|
|
|
# wired devices with no wire plugged in fail here
|
|
|
|
- name: Disconnect wired devices
|
|
|
|
shell: nmcli c down id "System{{ item|trim }}"
|
|
|
|
ignore_errors: True
|
2017-06-09 23:25:56 +00:00
|
|
|
when: item|trim != iiab_wireless_lan_iface and item|trim != iiab_wan_iface and wan_ip == "dhcp"
|
2017-05-27 18:09:50 +00:00
|
|
|
with_items:
|
2018-10-08 22:34:16 +00:00
|
|
|
- "{{ adapter_list.stdout_lines }}"
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
### keep at end.
|
|
|
|
### If dhcp fails the single interface will become LAN again because we didn't prevent the creation
|
|
|
|
# Now disable LAN if single interface
|
2017-10-27 16:08:35 +00:00
|
|
|
- name: DHCP found on Single interface forcing LAN disabled
|
2017-05-27 18:09:50 +00:00
|
|
|
set_fact:
|
2018-10-08 22:34:16 +00:00
|
|
|
iiab_lan_iface: "none"
|
|
|
|
when: dhcp_good and adapter_count.stdout|int == "1"
|