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
This commit is contained in:
Dmitriy Rabotyagov 2023-12-29 10:48:24 +01:00
parent a93a952652
commit 2e78c2314d
2 changed files with 11 additions and 1 deletions

View File

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

View File

@ -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) %}