aboutsummaryrefslogtreecommitdiffstats
path: root/roles/hostname/tasks
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-04-09 20:35:43 -0400
committerbnewbold <bnewbold@robocracy.org>2016-04-09 20:35:45 -0400
commit36de211ca5ff9a2c0add03ff923a5d43788c0ae6 (patch)
tree396932784bfb252be460384ea43df10847896059 /roles/hostname/tasks
parentde3755c284411432c7565fa0f01f1487abe65aaf (diff)
downloadinfra-36de211ca5ff9a2c0add03ff923a5d43788c0ae6.tar.gz
infra-36de211ca5ff9a2c0add03ff923a5d43788c0ae6.zip
import ansible-hostname role
Pretty ridiculous that this is required
Diffstat (limited to 'roles/hostname/tasks')
-rw-r--r--roles/hostname/tasks/main.yml24
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]