blob: 0fc8fbc4c358089a25e17465df9fae8bd205fbb7 (
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
27
28
29
30
31
32
33
|
---
- name: "Verify hostname"
command: hostnamectl status --static
register: hostname_fqdn
- name: "Set hostname if required"
when: hostname_fqdn.stdout != ansible_fqdn
block:
- name: Setting Hostname Fact
set_fact:
new_hostname: "{{ custom_hostname | default(inventory_hostname_short) }}"
- name: Setting FQDN Fact
set_fact:
new_fqdn: "{{ new_hostname }}.{{ full_dns_domain }}"
- name: Setting hostname and DNS domain
hostname: name="{{ new_fqdn }}"
- name: Check for cloud.cfg
stat: path=/etc/cloud/cloud.cfg
register: cloud_cfg
- name: Prevent cloud-init updates of hostname/fqdn (if applicable)
lineinfile:
dest: /etc/cloud/cloud.cfg
state: present
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^ - set_hostname', line: '# - set_hostname' }
- { regexp: '^ - update_hostname', line: '# - update_hostname' }
when: cloud_cfg.stat.exists == True
|