summaryrefslogtreecommitdiff
path: root/ansible/roles/trove-setup/tasks/hostname.yml
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-07-14 15:10:09 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-07-14 15:10:09 +0000
commit160fd3f2f1d372751836c0073bdc944df1cfbb91 (patch)
treed6b46ce1ec600400883e53b82e12b390fa73f262 /ansible/roles/trove-setup/tasks/hostname.yml
parenteafba37e2bfc3897e3e7f65f2ce087fbee358f43 (diff)
parentd349c9a35d3d53ebfc9f26df373e84fa5986a1b6 (diff)
downloadtrove-setup-160fd3f2f1d372751836c0073bdc944df1cfbb91.tar.gz
Merge branch 'baserock/pedroalvarez/trove-ansible3'
Reviewed-by: Richard Maw Reviewed-by: Lars Wirzenius
Diffstat (limited to 'ansible/roles/trove-setup/tasks/hostname.yml')
-rw-r--r--ansible/roles/trove-setup/tasks/hostname.yml26
1 files changed, 26 insertions, 0 deletions
diff --git a/ansible/roles/trove-setup/tasks/hostname.yml b/ansible/roles/trove-setup/tasks/hostname.yml
new file mode 100644
index 0000000..f4a11e2
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/hostname.yml
@@ -0,0 +1,26 @@
+# Depends on:
+# - check.yml
+---
+- name: Check the /etc/hostname and compare it with HOSTNAME (This task can fail)
+ shell: su -c '[ "$(cat /etc/hostname)" == '{{ HOSTNAME|quote|quote }}' ]'
+ register: hostname_file
+ ignore_errors: True
+ changed_when: False
+ when: HOSTNAME is defined
+
+# If /etc/hostname doesn't match with HOSTNAME
+- name: Rewrite /etc/hostname with HOSTNAME
+ shell: echo {{ HOSTNAME|quote }} > /etc/hostname
+ when: hostname_file|failed
+
+- name: Check the actual hostname with `hostname` and compare it with HOSTNAME (This task can fail)
+ shell: sh -c '[ "$(hostname)" == '{{ HOSTNAME|quote|quote }}' ]'
+ register: actual_hostname
+ ignore_errors: True
+ changed_when: False
+ when: HOSTNAME is defined
+
+# If `hostname` doesn't match with HOSTNAME
+- name: Change the hostname to HOSTNAME
+ shell: hostname {{ HOSTNAME|quote }}
+ when: actual_hostname|failed