mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-10 18:15:39 +00:00
Merge a16ba6eb1c into 3774ca20d2
This commit is contained in:
commit
e7dbcdc821
2 changed files with 25 additions and 1 deletions
|
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "udm_dns_record - normalize IPv6 addresses in ``data`` to expanded form to fix idempotency (https://github.com/ansible-collections/community.general/issues/317, https://github.com/ansible-collections/community.general/pull/12149)."
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue