mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-30 19:34:45 +00:00
dnsrecord: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the generated commands and also in the member failure handling for modules with member support.
This commit is contained in:
@@ -1241,7 +1241,7 @@ def create_reverse_ip_record(module, zone_name, name, ips):
|
|||||||
'idnsname': to_text(reverse_host),
|
'idnsname': to_text(reverse_host),
|
||||||
"ptrrecord": "%s.%s" % (name, zone_name)
|
"ptrrecord": "%s.%s" % (name, zone_name)
|
||||||
}
|
}
|
||||||
_cmds.append([reverse_zone, 'dnsrecord_add', rev_args])
|
_cmds.append([to_text(reverse_zone), 'dnsrecord_add', rev_args])
|
||||||
|
|
||||||
return _cmds
|
return _cmds
|
||||||
|
|
||||||
@@ -1408,6 +1408,14 @@ def define_commands_for_absent_state(module, zone_name, entry, res_find):
|
|||||||
return _commands
|
return _commands
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def exception_handler(module, ex):
|
||||||
|
if isinstance(ex, (ipalib_errors.EmptyModlist,
|
||||||
|
ipalib_errors.DuplicateEntry)):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Execute DNS record playbook."""
|
"""Execute DNS record playbook."""
|
||||||
ansible_module = configure_module()
|
ansible_module = configure_module()
|
||||||
@@ -1468,30 +1476,10 @@ def main():
|
|||||||
if cmds:
|
if cmds:
|
||||||
commands.extend(cmds)
|
commands.extend(cmds)
|
||||||
|
|
||||||
# Check mode exit
|
|
||||||
if ansible_module.check_mode:
|
|
||||||
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
|
||||||
|
|
||||||
# Execute commands
|
# Execute commands
|
||||||
for name, command, args in commands:
|
|
||||||
try:
|
|
||||||
result = ansible_module.ipa_command(
|
|
||||||
command, to_text(name), args)
|
|
||||||
if "completed" in result:
|
|
||||||
if result["completed"] > 0:
|
|
||||||
changed = True
|
|
||||||
else:
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
except ipalib_errors.EmptyModlist:
|
changed = ansible_module.execute_ipa_commands(
|
||||||
continue
|
commands, exception_handler=exception_handler)
|
||||||
except ipalib_errors.DuplicateEntry:
|
|
||||||
continue
|
|
||||||
except Exception as e:
|
|
||||||
error_message = str(e)
|
|
||||||
|
|
||||||
ansible_module.fail_json(
|
|
||||||
msg="%s: %s: %s" % (command, name, error_message))
|
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
ansible_module.exit_json(changed=changed, host=exit_args)
|
ansible_module.exit_json(changed=changed, host=exit_args)
|
||||||
|
|||||||
Reference in New Issue
Block a user