From a43183028558300268e4cf74fec9631d342c0406 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 30 Oct 2013 20:59:39 +0100 Subject: Configure /etc/{hosts,hostname,mailname}. --- roles/common/handlers/main.yml | 3 +++ roles/common/tasks/hosts.yml | 27 +++++++++++++++++++++++++++ roles/common/tasks/main.yml | 1 + roles/common/templates/etc/hostname.j2 | 1 + roles/common/templates/etc/mailname.j2 | 1 + 5 files changed, 33 insertions(+) create mode 100644 roles/common/handlers/main.yml create mode 100644 roles/common/tasks/hosts.yml create mode 100644 roles/common/templates/etc/hostname.j2 create mode 100644 roles/common/templates/etc/mailname.j2 (limited to 'roles') diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml new file mode 100644 index 0000000..e42534c --- /dev/null +++ b/roles/common/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: Refresh hostname + service: name=hostname.sh state=restarted diff --git a/roles/common/tasks/hosts.yml b/roles/common/tasks/hosts.yml new file mode 100644 index 0000000..18ccfd9 --- /dev/null +++ b/roles/common/tasks/hosts.yml @@ -0,0 +1,27 @@ +- name: Set hostname + template: src=etc/hostname.j2 + dest=/etc/hostname + owner=root group=root + mode=0644 + tags: hostname + notify: + - Refresh hostname + +- name: Set mailname + template: src=etc/mailname.j2 + dest=/etc/mailname + owner=root group=root + mode=0644 + tags: mailname + +- name: Fix /etc/hosts (1) + lineinfile: dest=/etc/hosts create=yes + regexp="^127\.0\.0\.1\s+" + line="127.0.0.1 localhost" + tags: hosts + +- name: Fix /etc/hosts (2) + lineinfile: dest=/etc/hosts create=yes + regexp="^127\.0\.1\.1\s+" + line="127.0.1.1 {{ inventory_hostname }} {{ inventory_hostname_short }}" + tags: hosts diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index acc9611..1abcbb6 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -1,2 +1,3 @@ --- - include: sysctl.yml tags=sysctl +- include: hosts.yml diff --git a/roles/common/templates/etc/hostname.j2 b/roles/common/templates/etc/hostname.j2 new file mode 100644 index 0000000..68fd234 --- /dev/null +++ b/roles/common/templates/etc/hostname.j2 @@ -0,0 +1 @@ +{{ inventory_hostname_short }} diff --git a/roles/common/templates/etc/mailname.j2 b/roles/common/templates/etc/mailname.j2 new file mode 100644 index 0000000..1fad51f --- /dev/null +++ b/roles/common/templates/etc/mailname.j2 @@ -0,0 +1 @@ +{{ inventory_hostname }} -- cgit v1.2.3