add support for netplan on ubuntu bionic
authorChristian Pointner <equinox@realraum.at>
Wed, 28 Nov 2018 01:20:44 +0000 (02:20 +0100)
committerChristian Pointner <equinox@realraum.at>
Wed, 28 Nov 2018 01:20:44 +0000 (02:20 +0100)
fixes #42

ansible/roles/vm/network/tasks/classic.yml [deleted file]
ansible/roles/vm/network/tasks/main.yml
ansible/roles/vm/network/tasks/netplan.yml [deleted file]
ansible/roles/vm/network/templates/netplan.yaml.j2 [new file with mode: 0644]

diff --git a/ansible/roles/vm/network/tasks/classic.yml b/ansible/roles/vm/network/tasks/classic.yml
deleted file mode 100644 (file)
index 4728bf4..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
----
-- 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
index 0171d11..9bef36e 100644 (file)
@@ -1,10 +1,43 @@
 ---
-- name: install classic network config
-  import_tasks: classic.yml
+- 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)
 
-- name: install basic netplan config
-  import_tasks: netplan.yml
+- 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
diff --git a/ansible/roles/vm/network/tasks/netplan.yml b/ansible/roles/vm/network/tasks/netplan.yml
deleted file mode 100644 (file)
index 0adf9f5..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
----
-- debug:
-    msg: "TODO ******* ADD ME ********"
diff --git a/ansible/roles/vm/network/templates/netplan.yaml.j2 b/ansible/roles/vm/network/templates/netplan.yaml.j2
new file mode 100644 (file)
index 0000000..0d78ab4
--- /dev/null
@@ -0,0 +1,10 @@
+# This file describes the network interfaces available on your system
+# For more information, see netplan(5).
+network:
+  version: 2
+  renderer: networkd
+  ethernets:
+    {{ network.primary.interface }}:
+      addresses: [ {{ (network.primary.ip + '/' + network.primary.mask) | ipaddr('address/prefix') }} ]
+      gateway4: {{ network.primary.gateway }}
+      accept-ra: false