From f996ae57b86061248951f71b727c84b5c46a9703 Mon Sep 17 00:00:00 2001 From: Lucas Costa Beyeler Date: Fri, 3 Feb 2017 23:42:15 -0200 Subject: [PATCH] Updating the playbook to edit the hostname --- .travis.yml | 6 ------ tasks/main.yml | 1 + tasks/nodistro/hostname.yml | 14 ++++++++++++++ templates/hosts.j2 | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 tasks/nodistro/hostname.yml create mode 100644 templates/hosts.j2 diff --git a/.travis.yml b/.travis.yml index 1170d76..756ed4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,12 +23,6 @@ install: # Create ansible.cfg with correct roles_path - printf '[defaults]\nroles_path=../' >ansible.cfg - - # Include the domain inside the /etc/hosts - - printf '127.0.0.1 localhost.localdomain localhost' > /etc/hosts - - # Change the hostname - - hostnamectl set-hostname 'localhost.localdomain' script: # Basic role syntax check diff --git a/tasks/main.yml b/tasks/main.yml index f4e991d..40f84e7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -10,6 +10,7 @@ # # Starting the install ################################### +- include: nodistro/hostname.yml - include: '{{ ansible_os_family }}/packages.yml' - include: nodistro/install-zimbra.yml - include: nodistro/install-spamassassin.yml diff --git a/tasks/nodistro/hostname.yml b/tasks/nodistro/hostname.yml new file mode 100644 index 0000000..0e8c368 --- /dev/null +++ b/tasks/nodistro/hostname.yml @@ -0,0 +1,14 @@ +# Change the hostname and ensure the /etc/hosts has the hostname linked to the +# localhost. This is very important for some services, like Zimbra, who will +# check for the LDAP Server's IP. + +- name: Correct the machine's hostname to {{ hostname }} + hostname: name='{{ hostname }}.{{ domain }}' + +- name: Changing the host's file for the template + template: + src: hosts.j2 + dest: /etc/hosts + owner: root + group: root + mode: 0644 diff --git a/templates/hosts.j2 b/templates/hosts.j2 new file mode 100644 index 0000000..a9fa22c --- /dev/null +++ b/templates/hosts.j2 @@ -0,0 +1,3 @@ +::1 localhost.localdomain localhost +127.0.0.1 localhost.localdomain localhost +127.0.0.1 {{ hostname }}.{{ domain }} {{ hostname }}