- include_tasks: detected_network.yml
  when: not installing   #REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml
  tags:
    - network            #REMOVE SUCH LINES (BELOW TOO) AS WE'RE IN "network" ?
    - network-discover

- name: IF WIFI IS PRIMARY GATEWAY, PLEASE RUN 'iiab-hotspot-on' MANUALLY
  set_fact:
    hostapd_enabled: False    # used in (1) hostapd.yml, (2) rpi_debian.yml +
                              # (3) its dhcpcd.conf.j2, (4) restart.yml
    no_net_restart: True      # used below in (1) sysd-netd-debian.yml,
                              # (2) debian.yml, (3) rpi_debian.yml
  when: discovered_wireless_iface == iiab_wan_iface and not reboot_to_AP
# EITHER WAY: hostapd_enabled's state is RECORDED into {{ iiab_env_file }}
# in hostapd.yml for later use by...
# /usr/libexec/iiab-startup.sh, iiab-hotspot-off & iiab-hotspot-on
#
# Separate Idea, Not Without Risks: should WiFi-as-gateway detection logic
# be encapsulated into roles/network/tasks/hostapd.yml in future?  Whereas
# today "./runtags hostapd" doesn't exist & "./runtags AP" is UNSUPPORTED!

#- name: RPi - reboot to AP post install - installed via wifi so the services are ready
#  set_fact:
#    iiab_lan_iface: br0
#    iiab_wan_iface: "{{ discovered_wired_iface }}"
#    iiab_wireless_lan_iface: "{{ discovered_wireless_iface }}"
#    iiab_wired_lan_iface: ""
#  when: is_rpi and discovered_wireless_iface is defined and discovered_wireless_iface == iiab_wan_iface and reboot_to_AP

- include_tasks: computed_network.yml
  when: not installing   #REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml
  tags:
    - network
    - network-discover

- include_tasks: hostapd.yml
  tags:
    - network
    - AP

#- name: RPi - don't reboot to AP post install - installed via wifi - don't blow away current network
#  set_fact:
#    no_net_restart: True
#    hostapd_enabled: False
#  when: is_rpi and discovered_wireless_iface is defined and discovered_wired_iface != iiab_wan_iface

##### Start static ip address info for first run #####
#- include_tasks: static.yml
#  when: 'iiab_wan_iface != "none" and wan_ip != "dhcp"'
##### End static ip address info

- include_tasks: hosts.yml
  tags:
    - network
    - hostname
    - domain

- name: Configure wondershaper
  include_tasks: wondershaper.yml
  when: wondershaper_install | bool
  tags:
    - network
    - wondershaper

- name: (Re)Install named
  include_tasks: named.yml
  when: named_install and FQDN_changed and iiab_stage|int == 9

- name: (Re)Install dhcpd
  include_tasks: dhcpd.yml
  when: dhcpd_install and FQDN_changed and iiab_stage|int == 9

- name: (Re)Install Squid
  include_tasks: squid.yml
  when: squid_install and FQDN_changed and iiab_stage|int == 9

#### start services
- include_tasks: avahi.yml
  tags:
    - network

- include_tasks: computed_services.yml
  tags:
    - network
    - named
    - dhcpd
    - dnsmasq
    - squid

- include_tasks: enable_services.yml
  tags:
    - network
    - named
    - dhcpd
    - dnsmasq
    - squid

#### end services
#### Start network layout
- name: Redhat networking
  include_tasks: ifcfg_mods.yml
  when: is_redhat | bool
  #and not installing
  tags:
    - network

- name: Netplan in use on Ubuntu 18.04+
  include_tasks: netplan.yml
  when: is_ubuntu and not is_ubuntu_16
  #when: is_ubuntu_18 | bool
  #and not installing
  tags:
    - network

- name: NetworkManager in use
  include_tasks: NM-debian.yml
  when: is_debuntu and network_manager_active
  #and not installing
  tags:
    - network

- name: systemd-networkd in use
  include_tasks: sysd-netd-debian.yml
  when: is_debuntu and systemd_networkd_active
  #and not installing
  tags:
    - network

- name: RPi's have dhcpcd in use
  include_tasks: rpi_debian.yml
  when: is_debuntu and is_rpi
  #and not installing
  tags:
    - network

- name: Not RPi, Not NetworkManager, Not systemd-networkd in use
  include_tasks: debian.yml
  when: (not is_rpi and not network_manager_active and not systemd_networkd_active and is_debuntu) or is_ubuntu_16
  #and not installing
  tags:
    - network

#### end network layout
- include_tasks: restart.yml
  when: not installing
  tags:
    - network
    - named
    - dhcpd
    - dnsmasq
    - squid
    - AP
