---
# linux-postinstall wpa_gui

# Install wpa_gui and disable NetwotkManager (NM)

- name: Install packages
  apt: >
    name="{{ item }}"
    state="present"
  with_items:
    - wpagui
    - wpasupplicant
  tags: lp_wpagui_packages

- name: Disable NM /etc/init/network-manager.override
  template: >
    src="network-manager-override.j2"
    dest="/etc/init/network-manager.override"
    owner="root"
    group="root"
    mode="0644"
  when: lp_wpagui|lower == "yes"
  tags: lp_wpagui_disableNM
  
- name: Configure managed=false in /etc/NetworkManager/NetworkManager.conf
  lineinfile: >
    dest="/etc/NetworkManager/NetworkManager.conf"
    regexp="^managed"
    line="managed=false"
  when: lp_wpagui|lower == "yes"
  tags: lp_wpagui_disableNM

- name: Stop and disable NM
  systemd: >
    name="network-manager"
    enabled="no"
    state="stopped"
  when: lp_wpagui|lower == "yes"
  tags: lp_wpagui_disableNM

# EOF
...

---
# linux-postinstall wpa_gui

# Install wpa_gui and disable NetwotkManager (NM)

- name: Install packages
  apt: >
    name="{{ item }}"
    state="present"
  with_items:
    - wpagui
    - wpasupplicant
  tags: lp_wpagui_packages

- name: Disable NM /etc/init/network-manager.override
  template: >
    src="network-manager-override.j2"
    dest="/etc/init/network-manager.override"
    owner="root"
    group="root"
    mode="0644"
  when: lp_wpagui|lower == "yes"
  tags: lp_wpagui_disableNM
  
- name: Configure managed=false in /etc/NetworkManager/NetworkManager.conf
  lineinfile: >
    dest="/etc/NetworkManager/NetworkManager.conf"
    regexp="^managed"
    line="managed=false"
  when: lp_wpagui|lower == "yes"
  tags: lp_wpagui_disableNM

- name: Stop and disable NM
  systemd: >
    name="network-manager"
    state="stopped"
    enabled="no"
  when: lp_wpagui|lower == "yes"
  tags: lp_wpagui_disableNM

- name: Stop and disable all NM services
  service: >
    name="{{ item }}"
    state="stopped"
    enabled="no"
  with_items:
    - NetworkManager.service
    - NetworkManager-dispatcher.service
    - NetworkManager-wait-online.service
  tags: lp_wpagui_disableNM

# EOF
...

Stop and disable all NM services when wpa_gui is installed.
Stop and disable all NM services when wpa_gui is installed.
