Skip to content

rabbitmq: keep dots in interface fact keys - #2575

Open
ideaship wants to merge 1 commit into
mainfrom
stack/1-interface-fact-key-dots
Open

rabbitmq: keep dots in interface fact keys#2575
ideaship wants to merge 1 commit into
mainfrom
stack/1-interface-fact-key-dots

Conversation

@ideaship

@ideaship ideaship commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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 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.

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.

Verification. 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. Reverting the code change makes the updated test fail with the message above.

Found while investigating:

🤖 Generated with Claude Code

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>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider renaming normalized_interface to something like ansible_fact_interface (or similar) now that it’s specifically aligned to Ansible’s fact naming, which will make the intent clearer than a generic “normalized” name.
  • Since the dash-to-underscore mapping logic is now tightly coupled to Ansible’s behavior, it might be worth extracting it into a small helper (e.g., to_ansible_interface_fact_key) so that any future changes to Ansible’s normalization rules need only be updated in one place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider renaming `normalized_interface` to something like `ansible_fact_interface` (or similar) now that it’s specifically aligned to Ansible’s fact naming, which will make the intent clearer than a generic “normalized” name.
- Since the dash-to-underscore mapping logic is now tightly coupled to Ansible’s behavior, it might be worth extracting it into a small helper (e.g., `to_ansible_interface_fact_key`) so that any future changes to Ansible’s normalization rules need only be updated in one place.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

2 participants