Skip to content

Commit 5bc0721

Browse files
committed
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 (cherry picked from commit 46bd052)
1 parent 6870d56 commit 5bc0721

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ansible/roles/baremetal/tasks/pre-install.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
marker: "# {mark} ANSIBLE GENERATED HOSTS"
2929
block: |
3030
{% for host in groups['baremetal'] %}
31-
{% set api_interface = hostvars[host]['api_interface'] %}
31+
{% set api_interface = hostvars[host]['api_interface'] | replace('-', '_') %}
3232
{% if host not in groups['bifrost'] or 'ansible_' + api_interface in hostvars[host] %}
3333
{% set hostnames = [hostvars[host]['ansible_nodename'], hostvars[host]['ansible_hostname']] %}
3434
{{ 'api' | kolla_address(host) }} {{ hostnames | unique | join(' ') }}
@@ -39,7 +39,7 @@
3939
- customize_etc_hosts | bool
4040
# Skip hosts in the bifrost group that do not have a valid api_interface.
4141
- inventory_hostname not in groups['bifrost'] or
42-
'ansible_' + hostvars[inventory_hostname]['api_interface'] in hostvars[inventory_hostname]
42+
'ansible_' + hostvars[inventory_hostname]['api_interface'] | replace('-', '_') in hostvars[inventory_hostname]
4343

4444
# NOTE(osmanlicilegi): The distribution might come with cloud-init installed, and manage_etc_hosts
4545
# configuration enabled. If so, it will override the file /etc/hosts from cloud-init templates at
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes an issue when generating ``/etc/hosts`` during ``kolla-ansible
5+
bootstrap-servers`` when one or more hosts has an ``api_interface`` with
6+
dashes (``-``) in its name. `LP#1927357
7+
<https://bugs.launchpad.net/kolla-ansible/+bug/1927357>`__

0 commit comments

Comments
 (0)