blob: f4a11e275d7e0429326fc7c91f9b2dcd2ea5487d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
|