Skip to content
Snippets Groups Projects
Commit 46bd0525 authored by Mark Goddard's avatar Mark Goddard
Browse files

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
parent 008ada90
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
---
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>`__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment