---

- name: Check if NetworkManager package is installed
  shell: dpkg -l network-manager
  register: nm_installed_check
  failed_when: nm_installed_check.rc > 1

- name: Stop NetworkManager
  service: name=network-manager state=stopped enabled=no
  when: nm_installed_check == 0

- name: Remove NetworkManager
  apt: pkg=network-manager
       state=absent

- name: Configure network interfaces
  template:
    src: etc_network_interfaces.j2
    dest: /etc/network/interfaces
    owner: root
    group: root
    mode: 0644
  notify: Restart network

---

- name: Check if NetworkManager package is installed
  command: dpkg -l network-manager
  register: nm_installed_check
  failed_when: nm_installed_check.rc > 1

- name: Stop NetworkManager
  service: name=network-manager state=stopped enabled=no
  when: nm_installed_check == 0

- name: Remove NetworkManager
  apt: pkg=network-manager
       state=absent

- name: Configure network interfaces
  template:
    src: etc_network_interfaces.j2
    dest: /etc/network/interfaces
    owner: root
    group: root
    mode: 0644
  notify: Restart network

Use command vs shell since it is safer
Use command vs shell since it is safer
