summaryrefslogtreecommitdiff
path: root/roles/vm/network/tasks/main.yml
blob: 527ccdfa84da517b3f247943eeab894422d3617e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
- block:
    - name: remove legacy systemd.link units
      loop:
        - 50-virtio-kernel-names.link
        - 99-default.link
      file:
        name: "/etc/systemd/network/{{ item }}"
        state: absent

    - name: install systemd network link units
      loop: "{{ network.systemd_link.interfaces }}"
      loop_control:
        label: "{{ item.name }}"
        index_var: interface_index
      template:
        src: systemd.link.j2
        dest: "/etc/systemd/network/{{ '%02d' | format(interface_index + 11) }}-{{ item.name }}.link"
      notify: rebuild initramfs

  when: network.systemd_link is defined

- name: install basic interface config
  template:
    src: interfaces.j2
    dest: /etc/network/interfaces
    mode: 0644
  when: ansible_distribution == "Debian" or (ansible_distribution == "Ubuntu" and (ansible_distribution_major_version | int) < 18)

- block:
    - name: remove default netplan config
      file:
        path: /etc/netplan/01-netcfg.yaml
        state: absent

    - name: install basic netplan config
      template:
        src: netplan.yaml.j2
        dest: "/etc/netplan/01-{{ network.primary.interface }}.yaml"
        mode: 0644

  when:  ansible_distribution == "Ubuntu" and (ansible_distribution_major_version | int) >= 18

- name: remove resolvconf package
  apt:
    name: resolvconf
    state: absent
    force_apt_get: yes
    purge: yes

- name: generate resolv.conf
  template:
    src: resolv.conf.j2
    dest: /etc/resolv.conf