# NM-debian.yml
- name: Stopping services
  include_tasks: down-debian.yml

# provide keyfile layout like the XO's used way back.
- name: Create uuid for NM's keyfile store
  shell: uuidgen
  register: uuid_response

- name: Put the uuid in place
  set_fact:
    gen_uuid: "{{ uuid_response.stdout_lines[0] }}"

# NM might have a watcher on this path and we don't have to restart NM
- name: Copy the bridge script for NetworkManager
  template:
    dest: /etc/NetworkManager/system-connections/
    src: network/bridge-br0
    mode: 0600
  when: iiab_network_mode != "Appliance"

- name: Remove br0 in Appliance Mode for NetworkManager
  file:
    dest: /etc/NetworkManager/system-connections/bridge-br0
    state: absent
  when: iiab_network_mode == "Appliance"

- name: Removing static for NetworkManager
  file:
    dest: /etc/NetworkManager/system-connections/iiab-static
    state: absent
  when: wan_ip == "dhcp"

- name: Static IP computing CIDR
  shell: netmask {{ wan_ip }}/{{ wan_netmask }} | awk -F "/" '{print $2}'
  register: CIDR
  when: wan_ip != "dhcp"

- name: Static IP setting CIDR
  set_fact:
    wan_cidr: "{{ CIDR.stdout }}"
  when: wan_ip != "dhcp"

- name: Create uuid for NM's keyfile store static
  shell: uuidgen
  register: uuid_response2
  when: wan_ip != "dhcp"

- name: Put the uuid in place
  set_fact:
    gen_uuid2: "{{ uuid_response2.stdout_lines[0] }}"
  when: wan_ip != "dhcp"

- name: Copy static template for NetworkManager
  template:
    dest: /etc/NetworkManager/system-connections/iiab-static
    src: network/NM-static.j2
    mode: 0600
  when: wan_ip != "dhcp"

- name: Stop wpa_supplicant service
  service:
    name: wpa_supplicant
    state: stopped
  when: iiab_wireless_lan_iface is defined and hostapd_enabled and iiab_network_mode != "Appliance"

- name: Mask wpa_supplicant
  shell: systemctl mask wpa_supplicant
  when: iiab_wireless_lan_iface is defined and hostapd_enabled and iiab_network_mode != "Appliance"

- name: Reload systemd
  systemd:
    daemon_reload: yes

- name: Restart the NetworkManager service
  systemd:
    name: network-manager
    state: restarted
  when: not nobridge is defined and not no_net_restart
