From 13541ea51bc25b48aae84eb4f8a404391712977a Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Sun, 22 Nov 2015 13:18:49 +0100
Subject: [PATCH] Cleanup known_hosts and host file

---
 tasks/cleanup.yml    | 20 ++++++++++++++++++++
 tasks/inithost.yml   |  4 ++++
 tasks/main.yml       |  2 ++
 tasks/removehost.yml |  5 +++++
 4 files changed, 31 insertions(+)
 create mode 100644 tasks/cleanup.yml
 create mode 100644 tasks/inithost.yml
 create mode 100644 tasks/removehost.yml

diff --git a/tasks/cleanup.yml b/tasks/cleanup.yml
new file mode 100644
index 0000000..3316c1a
--- /dev/null
+++ b/tasks/cleanup.yml
@@ -0,0 +1,20 @@
+---
+# file: cleanup.yml
+
+- name: "Remove host from known_hosts"
+  known_hosts:
+    name="{{ item }}"
+    state="absent"
+  with_items:
+    - '{{ static_ipv4|default(False) }}'
+    - '{{ host }}'
+
+- name: "Remove host from hosts file"
+  lineinfile:
+    dest=/etc/hosts
+    regexp='{{ item }}'
+    state=absent
+  sudo: yes
+  with_items:
+    - '^{{ static_ipv4|default(False) }} '
+    - '.*{{ host }}$'
diff --git a/tasks/inithost.yml b/tasks/inithost.yml
new file mode 100644
index 0000000..7c6ddac
--- /dev/null
+++ b/tasks/inithost.yml
@@ -0,0 +1,4 @@
+---
+# file: inithost.yml
+
+- include: "cleanup.yml"
diff --git a/tasks/main.yml b/tasks/main.yml
index e17fa56..947314d 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -2,3 +2,5 @@
 # file: roles/cloud/tasks/main.yml
 
 - include: "{{ cloud|default('none') }}/{{ mode }}.yml"
+
+- include: "{{ mode }}.yml"
diff --git a/tasks/removehost.yml b/tasks/removehost.yml
new file mode 100644
index 0000000..e0f71e6
--- /dev/null
+++ b/tasks/removehost.yml
@@ -0,0 +1,5 @@
+---
+# file: removehost.yml
+
+- include: "cleanup.yml"
+  when: are_you_sure == "YES"
-- 
GitLab