From 0531f80caf457831408367aaaedcc0446c00cdff Mon Sep 17 00:00:00 2001
From: Emil Renner Berthing <esmil@labitat.dk>
Date: Tue, 2 Oct 2018 17:42:08 +0200
Subject: space_server: networkd: delete leftover configuration

---
 roles/space_server/tasks/networkd.yml | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/roles/space_server/tasks/networkd.yml b/roles/space_server/tasks/networkd.yml
index cab8cae..318fbb5 100644
--- a/roles/space_server/tasks/networkd.yml
+++ b/roles/space_server/tasks/networkd.yml
@@ -6,6 +6,12 @@
     owner: root
     group: root
     mode: 0755
+
+- name: Register existing network configuration
+  find:
+    paths: '/etc/systemd/network'
+  register: networkd_existing
+
 - name: Configure network
   copy:
     dest: '/etc/systemd/network/'
@@ -14,6 +20,14 @@
     group: root
     mode: 0644
   with_fileglob: 'networkd/network/*'
+  register: networkd_created
+
+- name: Delete unneeded network configuration
+  file:
+    path: '{{ item }}'
+    state: absent
+  with_items: "{{ networkd_existing.files|map(attribute='path')|list }}"
+  when: "item not in networkd_created.results|map(attribute='dest')"
 
 - name: Create systemd-networkd-wait-online drop-in directory
   file:
-- 
cgit v1.2.1