-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathchange_hostname.yaml
39 lines (33 loc) · 1010 Bytes
/
change_hostname.yaml
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
27
28
29
30
31
32
33
34
35
36
37
38
39
---
- hosts: all
tasks:
- name: Change the hostname to our standard
hostname:
name="{{ inventory_hostname }}"
when:
ansible_fqdn != ansible_ssh_host
- name: restart machine
command: shutdown -r now "Ansible updates triggered"
async: 0
poll: 0
ignore_errors: True
when:
reboot is defined
- name: Waiting for server to come back up
local_action: wait_for host="{{ inventory_hostname }}" port=22 state=started
- name: Fix /etc/hosts removing the old hostname
tags:
- hosts
lineinfile:
state=present
dest=/etc/hosts
line="{{ ansible_default_ipv4.address }} {{ inventory_hostname }} {{ ansible_hostname }}"
regexp="^{{ ansible_default_ipv4.address }}"
when:
ansible_fqdn != inventory_hostname
- name: Validate ansible_fqdn == inventory_hostname
tags:
- validate
assert:
that:
ansible_fqdn == inventory_hostname