1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-06-14 11:57:40 +00:00

udm_dns_record: fix idempotency with shortened IPv6 addresses (#12149)

* fix(udm_dns_record): normalize IPv6 addresses before comparison

UCS stores IPv6 addresses in expanded form; providing a shortened address
causes obj.diff() to always detect a difference and report changed=True.
Normalize IPv6 values in the data dict to exploded form before updating
the Univention object.

Fixes #317

* changelog: add fragment for PR 12149

* add type hint
This commit is contained in:
Alexei Znamensky 2026-06-14 03:07:40 +12:00 committed by GitHub
parent 994b756026
commit 3fa258f5a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View file

@ -114,6 +114,28 @@ with deps.declare("ipaddress"):
import ipaddress
def _normalize_ip(value: str) -> str:
try:
addr = ipaddress.ip_address(value)
if isinstance(addr, ipaddress.IPv6Address):
return addr.exploded
except ValueError:
pass
return value
def _normalize_data_ips(data: dict) -> dict:
result: dict = {}
for key, value in data.items():
if isinstance(value, list):
result[key] = [_normalize_ip(v) if isinstance(v, str) else v for v in value]
elif isinstance(value, str):
result[key] = _normalize_ip(value)
else:
result[key] = value
return result
def main():
module = AnsibleModule(
argument_spec=dict(
@ -185,7 +207,7 @@ def main():
else:
obj["name"] = name
obj.update(data)
obj.update(_normalize_data_ips(data))
diff = obj.diff()
changed = obj.diff() != []
if not module.check_mode: