summaryrefslogtreecommitdiff
path: root/roles/vm/network/tasks/main.yml
blob: 9bef36ed8363a6abb1bfb6c9055031ea78e0a3f5 (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
---
- block:
    - name: remove legacy systemd.link units
      with_items:
        - 50-virtio-kernel-names.link
        - 99-default.link
      file:
        name: "/etc/systemd/network/{{ item }}"
        state: absent

    - name: install systemd network link units
      with_items: "{{ network.systemd_link.interfaces }}"
      loop_control:
        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
    purge: yes

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