Prevent cloud-init from overwriting hostname
This commit is contained in:
parent
d6bd3862eb
commit
c3356c957a
|
@ -3,6 +3,19 @@
|
|||
hostname:
|
||||
name: '{{ inventory_hostname | replace("_", "-") }}'
|
||||
|
||||
- name: check if rules file exists
|
||||
stat:
|
||||
path: /etc/cloud/cloud.cfg
|
||||
register: cloud_cfg
|
||||
|
||||
- name: Prevent cloud-init hostname setting
|
||||
lineinfile:
|
||||
dest: /etc/cloud/cloud.cfg
|
||||
regexp: '^preserve_hostname:'
|
||||
line: 'preserve_hostname: true'
|
||||
state: present
|
||||
when: cloud_cfg.stat.exists
|
||||
|
||||
- name: Add hostname to /etc/hosts
|
||||
lineinfile:
|
||||
dest: /etc/hosts
|
||||
|
|
Loading…
Reference in New Issue