aboutsummaryrefslogblamecommitdiffstats
path: root/roles/debian/tasks/networkd.yml
blob: 50791b3542570cce9a17f91b933d08ad95609c9a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
   










                                                           










                                                                                              
                   
 









                                                                                                          
                                                                 



















                                                                                  









                                                 
                                         

                        
---
- name: Configure systemd-networkd
  ini_file:
    path: '/etc/systemd/networkd.conf'
    no_extra_spaces: yes
    section: "{{ item.key.split('.',1)[0] }}"
    option:  "{{ item.key.split('.',1)[1] }}"
    value:   "{{ item.value|ternary(item.value,omit) }}"
    state:   "{{ item.value|ternary('present','absent') }}"
  with_dict: '{{ networkd_conf }}'
  when: use_networkd|bool

- name: Enable/disable systemd-networkd
  systemd:
    name: systemd-networkd.service
    enabled: "{{ use_networkd|ternary('yes','no') }}"
    masked:  "{{ use_networkd|ternary('no',omit) }}"
    # let the current network daemons run undisturbed until reboot
    # aka. don't cut the pipe we're connected through
    #state:  "{{ use_networkd|ternary('started','stopped') }}"
  when: not chroot
- name: '- when in chroot'
  command: "systemctl {{ use_networkd|ternary('enable','disable') }} systemd-networkd.service"
  when: chroot|bool

# in Debian 9 (stretch) we need to enable this manually
# this is fixed in buster though
- name: Enable/disable systemd-networkd-wait-online
  systemd:
    name: systemd-networkd-wait-online.service
    enabled: "{{ use_networkd|ternary('yes','no') }}"
    masked: no
  when: ansible_distribution_release == 'stretch' and not chroot
- name: '- when in chroot'
  command: "systemctl {{ use_networkd|ternary('enable','disable') }} systemd-networkd-wait-online.service"
  when: ansible_distribution_release == 'stretch' and chroot|bool

# use RequiredForOnline in systemd.network files if possible,
# but for older systemd's set networkd_ignore: ['eth0', 'eth1']
- name: Create/remove /etc/systemd/system/systemd-networkd-wait-online.service.d
  file:
    dest: '/etc/systemd/system/systemd-networkd-wait-online.service.d'
    state: "{{ (networkd_ignore|length > 0)|ternary('directory','absent') }}"
    owner: root
    group: root
    mode: 0755
- name: Don't wait for certain interfaces
  template:
    dest: '/etc/systemd/system/systemd-networkd-wait-online.service.d/ignore.conf'
    src: networkd-ignore.conf.j2
    owner: root
    group: root
    mode: 0644
  when: networkd_ignore|length > 0

# if we use networkd, make sure the networking service is disabled
- name: Mask Debian networking.service
  systemd:
    name: networking.service
    enabled: no
    masked: yes
  when: use_networkd and not chroot
- name: '- when in chroot'
  block:
  - command: systemctl disable networking.service
  - command: systemctl mask networking.service
  when: use_networkd|bool and chroot|bool

# vim: set ts=2 sw=2 et: