---
- name: Install NetworkManager and dependencies
  pacman:
    name:
      - networkmanager
      - networkmanager-openvpn
      - network-manager-applet
      - xfce4-notifyd
      - gnome-keyring
    state: present

- name: Push connectivity check config
  template:
      src: connectivity.conf.j2
      dest: /etc/NetworkManager/conf.d/20-connectivity.conf

- name: Push MAC address randomization config
  template:
      src: random_mac.conf.j2
      dest: /etc/NetworkManager/conf.d/20-random_mac.conf

- name: Push WiFi/Wired Exclusive dispatcher
  copy:
    src: wifi-wired-exclusive.sh
    dest: /etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive
    mode: 0755
  when: network.wifi_wired_exclusive is defined and network.wifi_wired_exclusive == True

- name: Enable and start NetworkManager
  service:
      name: NetworkManager.service
      enabled: yes
      state: started

- name: Enable and start NetworkManager dispatcher
  service:
      name: NetworkManager-dispatcher.service
      enabled: yes
      state: started

- name: Disable dhcpcd service
  service:
      name: dhcpcd.service
      enabled: no
