diff options
Diffstat (limited to 'roles/hostname/tasks')
-rw-r--r-- | roles/hostname/tasks/main.yml | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/roles/hostname/tasks/main.yml b/roles/hostname/tasks/main.yml new file mode 100644 index 0000000..02094f0 --- /dev/null +++ b/roles/hostname/tasks/main.yml @@ -0,0 +1,24 @@ +--- +- name: Keep temporary old hostname in /etc/hosts + lineinfile: + dest=/etc/hosts + regexp="^127\.0\.1\.1(.*)" + line="127.0.1.1{{'\t'}}{{ hostname_name }}{% if hostname_name != hostname_fqdn %}{{'\t'}}{{ hostname_fqdn }}{% endif %}\1" + state=present + backup=yes + backrefs=yes + when: ansible_hostname != hostname_name + tags: [configuration,hostname] + +- name: Set hostname + hostname: name={{ hostname_name }} + when: hostname_name is defined + tags: [configuration,hostname] + +- name: Update /etc/hosts + lineinfile: + dest=/etc/hosts + regexp="^127\.0\.1\.1" + line="127.0.1.1{{'\t'}}{{ hostname_name }}{% if hostname_name != hostname_fqdn %}{{'\t'}}{{ hostname_fqdn }}{% endif %}" + state=present + tags: [configuration,hostname] |