Damned, cloud-init is messing with /etc/hosts...

This commit is contained in:
Julien Palard 2024-02-26 10:42:30 +01:00
parent 5db7cca782
commit 19b5776760
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
2 changed files with 16 additions and 5 deletions

View File

@ -4,20 +4,31 @@
hostname:
name: "{{ inventory_hostname_short }}"
- name: Configure localhots
- name: Configure localhost
lineinfile:
path: /etc/hosts
regexp: '^127\.0\.0\.1'
line: "127.0.0.1 localhost"
owner: root
group: root
mode: 0644
- name: Configure FQDN
lineinfile:
path: /etc/hosts
regexp: '^127\.0\.1\.1'
line: "127.0.1.1 {{ inventory_hostname }} {{ inventory_hostname_short }}"
- name: Check if cloud-init is installed
ansible.builtin.stat:
path: /etc/cloud/cloud.cfg.d/
register: cloud_cfg
- name: Stop cloud-init to change hostname and /etc/hosts
when: cloud_cfg.stat.isdir is defined and cloud_cfg.stat.isdir
copy:
content: |
# Managed by Ansible
preserve_hostname: true
manage_etc_hosts: false
dest: /etc/cloud/cloud.cfg.d/02_ansible.cfg
owner: root
group: root
mode: 0644

View File

@ -1,5 +1,5 @@
---
exim4_sendonly_fqdn: '{{ ansible_fqdn }}'
exim4_sendonly_fqdn: '{{ inventory_hostname }}'
exim4_sendonly_smarthost: ''
exim4_sendonly_username: ''