Skip to content

Commit f7e49be

Browse files
committed
rabbitmq: keep dots in interface fact keys
get_rabbitmq_node_addresses() derived the ansible fact name for an interface by replacing both "-" and "." with "_": normalized_interface = internal_interface.replace(".", "_").replace("-", "_") Ansible only replaces "-". PrefixFactNamespace._underscore() is def _underscore(self, name): return name.replace('-', '_') and the setup module prefixes the result with "ansible_", so an interface named br-ex is ansible_br_ex -- but one named bond0.100 is ansible_bond0.100, with the dot intact. Dotted names are the conventional way to name a VLAN interface, so for any deployment using bond0.<vlan> the lookup asked for ansible_bond0_100, found nothing, and reported Interface bond0.100 (ansible_bond0_100) not found in ansible facts This is independent of the Jinja2 handling further up the function: it happens even when internal_interface is a plain literal with no template in it at all. Drop the dot substitution and keep the dash one. The unit test asserted the old mapping ("eth0.100" -> "ansible_eth0_100"), so it pinned the bug in place; it now asserts the mapping Ansible actually uses. Verified against live fact gathering on ansible-core 2.18.9 and 2.19.11: a real interface named br-e4aefb861457 is cached as ansible_br_e4aefb861457, and PrefixFactNamespace leaves eth0.100 as ansible_eth0.100. Assisted-by: Claude:claude-opus-5 Signed-off-by: Roger Luethi <luethi@osism.tech>
1 parent 0a164c5 commit f7e49be

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

osism/utils/rabbitmq.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ def get_rabbitmq_node_addresses():
9292

9393
logger.debug(f"Internal interface for {host}: {internal_interface}")
9494

95-
# Look for the interface in ansible facts
96-
# Interface names with special chars are normalized (e.g., eth0.100 -> ansible_eth0_100)
97-
normalized_interface = internal_interface.replace(".", "_").replace(
98-
"-", "_"
99-
)
95+
# Look for the interface in ansible facts. Ansible replaces "-"
96+
# with "_" in fact names and leaves dots alone
97+
# (PrefixFactNamespace._underscore), so "br-ex" is
98+
# ansible_br_ex while "bond0.100" is ansible_bond0.100.
99+
normalized_interface = internal_interface.replace("-", "_")
100100
interface_key = f"ansible_{normalized_interface}"
101101

102102
interface_facts = facts.get(interface_key)

tests/unit/utils/test_rabbitmq.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,18 @@ def test_template_traversal_hits_non_dict_skips_host(
346346
_assert_error_logged(loguru_logs, "Could not resolve template")
347347

348348
@pytest.mark.parametrize(
349-
"interface,normalized_key",
350-
[("eth0.100", "ansible_eth0_100"), ("eth-0", "ansible_eth_0")],
349+
"interface,fact_key",
350+
[("eth0.100", "ansible_eth0.100"), ("eth-0", "ansible_eth_0")],
351351
)
352-
def test_interface_name_normalized_for_fact_lookup(
353-
self, setup_addresses, loguru_logs, interface, normalized_key
352+
def test_interface_name_mapped_to_fact_key(
353+
self, setup_addresses, loguru_logs, interface, fact_key
354354
):
355-
# Facts are only stored under the normalized key, so a correct lookup
356-
# is the only way the address can be found.
355+
# Facts are only stored under the key Ansible actually uses, so a
356+
# correct mapping is the only way the address can be found. Ansible
357+
# replaces "-" with "_" and keeps dots.
357358
setup_addresses(
358359
hosts=["host1"],
359-
redis_side_effect=[_facts(normalized_key, "10.0.0.7")],
360+
redis_side_effect=[_facts(fact_key, "10.0.0.7")],
360361
check_output=[_GROUP_LISTING, _hostvars(interface)],
361362
)
362363

0 commit comments

Comments
 (0)