Use management_address instead of ansible_host for hosts files

In case where SSH address != management address current behavior of
hosts generation, is that a record pointing to the node SSH address
will be produced for metal hosts, as  ansible_host is set to the SSH
address.

This may result in an unexpected behavior, like live migrations
will be executed over the wrong network, as well as communication
can be simply firewalled.

Using `management_address` by default will ensure that hosts records
will be created to the internal network which is "designed" to
handle all internal communications.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-lxc_hosts/+/970366
Change-Id: I8a80d444072817af7a1d6f90c7ba2871e41c2dfd
Signed-off-by: Dmitriy Rabotyagov <dmitriy.rabotyagov@cleura.com>
This commit is contained in:
Dmitriy Rabotyagov committed 2025-12-10 18:33:16 +00:00
1 parent f220ab8fbe
commit 96f2065e5d
1 file changed
+2 -2
+2 -2
View File
@@ -22,9 +22,9 @@
{% set _ = _groups.remove('localhost') %}
{% for item in _groups %}
{% set record = [] %}
{% set _target_rfc_name = item|replace('_', '-') %}
{% set _target_rfc_name = item | replace('_', '-') %}
{% set _ans_hostname = hostvars[item]['ansible_facts']['hostname'] | default(_target_rfc_name) %}
{% set _ = record.append(hostvars[item]['ansible_host'] | default('127.0.0.1')) %}
{% set _ = record.append(hostvars[item]['management_address'] | default(hostvars[item]['ansible_host'] | default('127.0.0.1'))) %}
{% set _ = record.append(_ans_hostname ~ '.' ~ openstack_domain) %}
{% set _ = record.append(_target_rfc_name) %}
{% if (_ans_hostname != _target_rfc_name) and (_target_rfc_name != item) %}