Handle IP addresses configured on disappeared interfaces (#391)
Some checks failed
Collection Docs / Build Ansible Docs (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled
nox / ansible-test (push) Has been cancelled
Collection Docs / Publish Ansible Docs (push) Has been cancelled

* Handle IP addresses configured on disappeared interfaces

* Handle IP addresses configured on disappeared interfaces

Always set type property, add changelog fragment

* Handle IP addresses configured on disappeared interfaces (wording)

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Claudio Luck <claudio.luck@datact.ch>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Claudio Luck 2025-08-19 22:46:38 +02:00 committed by GitHub
parent fb070e4ac6
commit f6aeae1abd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View file

@ -0,0 +1,12 @@
---
bugfixes:
- |
api_facts - also report interfaces that are inferred only by reference by IP addresses.
RouterOS's APIs have IPv4 and IPv6 addresses point at interfaces by their name, which can
change over time and in-between API calls, such that interfaces may have been enumerated
under another name, or not at all (for example when removed). Such interfaces are now reported
under their new or temporary name and with a synthetic ``type`` property set to differentiate
the more likely and positively confirmed removal case (with ``type: "ansible:unknown"``) from
the unlikely and probably transient naming mismatch (with ``type: "ansible:mismatch"``).
Previously, the api_facts module would have crashed with a ``KeyError`` exception
(https://github.com/ansible-collections/community.routeros/pull/391).

View file

@ -317,8 +317,10 @@ class Interfaces(FactsBase):
def populate_addresses(self, data, family):
for value in data:
key = value['interface']
if family not in self.facts['interfaces'][key]:
self.facts['interfaces'][key][family] = []
iface = self.facts['interfaces'].setdefault(key, (
{"type": "ansible:unknown"} if key.startswith('*') else
{"type": "ansible:mismatch"}))
iface_addrs = iface.setdefault(family, [])
addr, subnet = value['address'].split('/')
subnet = subnet.strip()
# Try to convert subnet to an integer
@ -328,7 +330,7 @@ class Interfaces(FactsBase):
pass
ip = dict(address=addr.strip(), subnet=subnet)
self.add_ip_address(addr.strip(), family)
self.facts['interfaces'][key][family].append(ip)
iface_addrs.append(ip)
def add_ip_address(self, address, family):
if family == 'ipv4':