gandi_livedns: implement diff mode support (#11934)

* feat(gandi_livedns): implement diff mode support

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(gandi_livedns): add changelog fragment for PR 11934

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Update plugins/modules/gandi_livedns.py

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

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky
2026-05-03 12:49:39 +12:00
committed by GitHub
parent d7f248fb01
commit 0ebd32373d
3 changed files with 26 additions and 12 deletions

View File

@@ -0,0 +1,2 @@
minor_changes:
- gandi_livedns - add support for diff mode, showing before and after state of DNS records (https://github.com/ansible-collections/community.general/issues/4927, https://github.com/ansible-collections/community.general/pull/11934).

View File

@@ -168,6 +168,7 @@ class GandiLiveDNSAPI:
if records:
cur_record = records[0]
before = cur_record
self.changed = True
@@ -177,14 +178,14 @@ class GandiLiveDNSAPI:
# Removing one or more values from a record, we update the record with the remaining values
self.update_record(record, type, list(new_values), cur_record["rrset_ttl"], domain)
records = self.get_records(record, type, domain)
return records[0], self.changed
return before, records[0], self.changed
if not self.module.check_mode:
self.delete_record(record, type, domain)
else:
cur_record = None
before = None
return None, self.changed
return before, None, self.changed
def ensure_dns_record(self, record, type, ttl, values, domain):
if record == "":
@@ -194,6 +195,7 @@ class GandiLiveDNSAPI:
if records:
cur_record = records[0]
before = cur_record
do_update = False
if ttl is not None and cur_record["rrset_ttl"] != ttl:
@@ -210,10 +212,11 @@ class GandiLiveDNSAPI:
records = self.get_records(record, type, domain)
result = records[0]
self.changed = True
return result, self.changed
return before, result, self.changed
else:
return cur_record, self.changed
return before, cur_record, self.changed
before = None
if self.module.check_mode:
new_record = dict(rrset_type=type, rrset_name=record, rrset_values=values, rrset_ttl=ttl)
result = new_record
@@ -221,4 +224,4 @@ class GandiLiveDNSAPI:
result = self.create_record(record, type, values, ttl, domain)
self.changed = True
return result, self.changed
return before, result, self.changed

View File

@@ -20,7 +20,8 @@ attributes:
check_mode:
support: full
diff_mode:
support: none
support: full
version_added: 13.0.0
options:
personal_access_token:
description:
@@ -189,24 +190,32 @@ def main():
gandi_api = GandiLiveDNSAPI(module)
domain = module.params["domain"]
if module.params["state"] == "present":
ret, changed = gandi_api.ensure_dns_record(
before, ret, changed = gandi_api.ensure_dns_record(
module.params["record"],
module.params["type"],
module.params["ttl"],
module.params["values"],
module.params["domain"],
domain,
)
else:
ret, changed = gandi_api.delete_dns_record(
module.params["record"], module.params["type"], module.params["values"], module.params["domain"]
before, ret, changed = gandi_api.delete_dns_record(
module.params["record"], module.params["type"], module.params["values"], domain
)
result = dict(
changed=changed,
)
if ret:
result["record"] = gandi_api.build_result(ret, module.params["domain"])
result["record"] = gandi_api.build_result(ret, domain)
if module._diff:
result["diff"] = {
"before": gandi_api.build_result(before, domain) or {},
"after": result.get("record") or {},
}
module.exit_json(**result)