1
0
Fork 0

Prevent cloud-init from overwriting hostname

This commit is contained in:
Andrew Tomaka 2022-12-22 19:31:20 -05:00
parent d6bd3862eb
commit c3356c957a
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
2 changed files with 14 additions and 0 deletions

View file

@ -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

View file

@ -8,6 +8,7 @@
cache_valid_time: 3600
roles:
- role: instance
tags: instance
- role: apt
- role: firewall
- role: administrators