---
# tasks file for networkd

- name: Assertions
  assert:
    that:
        - ansible_os_family == 'Debian'
        - ansible_distribution_major_version >= 8
        - ansible_service_mgr == 'systemd'

- name: APT install
  with_items:
      - libnss-myhostname
      - libnss-resolve
  apt:
      name: '{{ item }}'
      state: present
      update_cache: yes
      cache_valid_time: 3600

- name: Configure network interfaces
  with_fileglob:
      - '{{ role_path }}/templates/networkd/*.netdev'
      - '{{ playbook_dir }}/templates/networkd/*.netdev'
      - '{{ role_path }}/templates/networkd/*.network'
      - '{{ playbook_dir }}/templates/networkd/*.network'
      - '{{ role_path }}/templates/networkd/*.link'
      - '{{ playbook_dir }}/templates/networkd/*.link'
  template:
      src: '{{ item }}'
      dest: '/etc/systemd/network/{{ item|basename }}'
      owner: root
      group: root
      mode: 0o0644
  notify:
      - Restart Systemd-networkd

- name: Disable ifupdown, enable networkd
  with_items:
      - name: systemd-resolved
        state: started
        enabled: yes
      - name: systemd-networkd
        state: started
        enabled: yes
      - name: networking
        enabled: no
  service:
      name: '{{ item.name }}'
      state: '{{ item.state|default(omit) }}'
      enabled: '{{ item.enabled }}'
