From 2e78c2314d65229810ad203419243962074c9246 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 29 Dec 2023 10:48:24 +0100 Subject: [PATCH] Remove `localhost` record from hosts file After adding `localhost` to inventory explicitly [1] this caused an interesting side-effect, where a record for `localhost` is being added to the managed block in /etc/hosts file, which might override FQDN defenition for the host. This also makes healthcheck-hosts.yml fail the test, since expected record is not present. [1] https://review.opendev.org/c/openstack/openstack-ansible/+/899523 Change-Id: If1840530a54aa9ae22eda1d3094f0c40ab66ddde --- .../do_not_add_localhost_to_hosts-36e365b95dc9da42.yaml | 8 ++++++++ tasks/openstack_update_hosts_file.yml | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/do_not_add_localhost_to_hosts-36e365b95dc9da42.yaml diff --git a/releasenotes/notes/do_not_add_localhost_to_hosts-36e365b95dc9da42.yaml b/releasenotes/notes/do_not_add_localhost_to_hosts-36e365b95dc9da42.yaml new file mode 100644 index 00000000..3c0a5758 --- /dev/null +++ b/releasenotes/notes/do_not_add_localhost_to_hosts-36e365b95dc9da42.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + After adding ``localhost`` to inventory explicitly this resulted in potential + FQDN change due to adding a record for localhost into managed block inside + ``/etc/hosts`` file. + This is now fixed and record for ``127.0.0.1`` will be removed from managed + by Ansible blocks inside /etc/hosts file. diff --git a/tasks/openstack_update_hosts_file.yml b/tasks/openstack_update_hosts_file.yml index 8ab98906..79fd1786 100644 --- a/tasks/openstack_update_hosts_file.yml +++ b/tasks/openstack_update_hosts_file.yml @@ -18,7 +18,9 @@ set_fact: _etc_hosts_content: |- {% set records = openstack_host_custom_hosts_records %} - {% for item in groups['all'] %} + {% set _groups = groups['all'] %} + {% set _ = _groups.remove('localhost') %} + {% for item in _groups %} {% set record = [] %} {% set _target_rfc_name = item|replace('_', '-') %} {% set _ans_hostname = hostvars[item]['ansible_facts']['hostname'] | default(_target_rfc_name) %}