瀏覽代碼

Create /etc/hosts from template

Markus Lindenberg 9 年之前
父節點
當前提交
b99963ac7c
共有 2 個文件被更改,包括 9 次插入2 次删除
  1. 2 2
      roles/common-net/tasks/hostname.yml
  2. 7 0
      roles/common-net/templates/hosts.j2

+ 2 - 2
roles/common-net/tasks/hostname.yml

@@ -3,5 +3,5 @@
 - name: Ensure hostname is set
   hostname: name={{ inventory_hostname_short }}
 
-- name: Ensure /etc/hosts entry for hostname exists
-  lineinfile: dest=/etc/hosts regexp="^127\\.0\\.1\\.1" line="127.0.1.1 {{ inventory_hostname }} {{ inventory_hostname_short }}"
+- name: ensure hostname is configured in /etc/hosts
+  template: src=hosts.j2 dest=/etc/hosts

+ 7 - 0
roles/common-net/templates/hosts.j2

@@ -0,0 +1,7 @@
+127.0.0.1   localhost
+127.0.1.1   {{ inventory_hostname }} {{ inventory_hostname_short }}
+
+# The following lines are desirable for IPv6 capable hosts
+::1     localhost ip6-localhost ip6-loopback
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters