baremetal: fix /etc/hosts generation when api_interface has dashes

Interface names with dashes can cause problems in Ansible since dashes
are replaced with underscores when referencing facts. In the baremetal
role we reference the fact for api_interface without replacing dashes
with underscores. This may result in host entries being omitted from
/etc/hosts.

This change fixes the issue.

Change-Id: I667adc7d8a7dbd20dbfa293f389e02355f8275bb
Related-Bug: #1927357
This commit is contained in:
Mark Goddard 2021-06-04 17:05:24 +01:00
parent 008ada9062
commit 46bd05250d
2 changed files with 9 additions and 2 deletions

View File

@ -28,7 +28,7 @@
marker: "# {mark} ANSIBLE GENERATED HOSTS"
block: |
{% for host in groups['baremetal'] %}
{% set api_interface = hostvars[host]['api_interface'] %}
{% set api_interface = hostvars[host]['api_interface'] | replace('-', '_') %}
{% if host not in groups['bifrost'] or 'ansible_' + api_interface in hostvars[host] %}
{% set hostnames = [hostvars[host]['ansible_nodename'], hostvars[host]['ansible_hostname']] %}
{{ 'api' | kolla_address(host) }} {{ hostnames | unique | join(' ') }}
@ -39,7 +39,7 @@
- customize_etc_hosts | bool
# Skip hosts in the bifrost group that do not have a valid api_interface.
- inventory_hostname not in groups['bifrost'] or
'ansible_' + hostvars[inventory_hostname]['api_interface'] in hostvars[inventory_hostname]
'ansible_' + hostvars[inventory_hostname]['api_interface'] | replace('-', '_') in hostvars[inventory_hostname]
# NOTE(osmanlicilegi): The distribution might come with cloud-init installed, and manage_etc_hosts
# configuration enabled. If so, it will override the file /etc/hosts from cloud-init templates at

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes an issue when generating ``/etc/hosts`` during ``kolla-ansible
bootstrap-servers`` when one or more hosts has an ``api_interface`` with
dashes (``-``) in its name. `LP#1927357
<https://bugs.launchpad.net/kolla-ansible/+bug/1927357>`__