From 283d6db5ea983a224cbdc8e360783bebd64fbcfa Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Fri, 10 May 2019 19:24:38 -0700
Subject: [PATCH] Insert the hostname into /etc/hosts near the top

---
 tasks/main.yml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tasks/main.yml b/tasks/main.yml
index 74b775d..07a853a 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -18,9 +18,10 @@
     - name: Update /etc/hosts to use new hostname
       lineinfile:
         dest: /etc/hosts
-        regexp: '^127.0.1.1'
-        line: '127.0.1.1 {{ hostname }}'
+        regexp: '^127.0.1.1\s{{ hostname }}'
+        line: "127.0.1.1\t{{ hostname }}"
         state: present
+        insertafter: "^127.0.0.1\t"
     - name: Set 'ansible_hostname' fact to the new hostname
       set_fact:
         ansible_hostname: '{{ hostname }}'
-- 
GitLab