mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-25 00:44:42 +00:00
Enabled Ansible check_mode
Added code to the ipa* plugins to support Ansible's check_mode, by means of a clean exit before the execution of the actual list of commands that would otherwise create/update/delete IPA servers and/or its resources.
This commit is contained in:
@@ -428,6 +428,7 @@ def main():
|
|||||||
if params \
|
if params \
|
||||||
and not compare_args_ipa(ansible_module, params, res_show):
|
and not compare_args_ipa(ansible_module, params, res_show):
|
||||||
changed = True
|
changed = True
|
||||||
|
if not ansible_module.check_mode:
|
||||||
api_command_no_name(ansible_module, "config_mod", params)
|
api_command_no_name(ansible_module, "config_mod", params)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -310,6 +310,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ def main():
|
|||||||
# Execute command only if configuration changes.
|
# Execute command only if configuration changes.
|
||||||
if not compare_args_ipa(ansible_module, args, res_find):
|
if not compare_args_ipa(ansible_module, args, res_find):
|
||||||
try:
|
try:
|
||||||
|
if not ansible_module.check_mode:
|
||||||
api_command_no_name(ansible_module, 'dnsconfig_mod', args)
|
api_command_no_name(ansible_module, 'dnsconfig_mod', args)
|
||||||
# If command did not fail, something changed.
|
# If command did not fail, something changed.
|
||||||
changed = True
|
changed = True
|
||||||
|
|||||||
@@ -380,6 +380,12 @@ def main():
|
|||||||
[name, 'dnsforwardzone_remove_permission', {}]
|
[name, 'dnsforwardzone_remove_permission', {}]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0,
|
||||||
|
**exit_args)
|
||||||
|
|
||||||
|
# Execute commands
|
||||||
for name, command, args in commands:
|
for name, command, args in commands:
|
||||||
api_command(ansible_module, command, name, args)
|
api_command(ansible_module, command, name, args)
|
||||||
changed = True
|
changed = True
|
||||||
|
|||||||
@@ -1496,6 +1496,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:
|
for name, command, args in commands:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -616,6 +616,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -500,6 +500,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
||||||
|
|
||||||
# Execute commands
|
# Execute commands
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|||||||
@@ -195,6 +195,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -300,6 +300,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
||||||
|
|
||||||
# Execute commands
|
# Execute commands
|
||||||
errors = []
|
errors = []
|
||||||
for name, command, args in commands:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -1347,6 +1347,10 @@ def main():
|
|||||||
|
|
||||||
del host_set
|
del host_set
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
||||||
|
|
||||||
# Execute commands
|
# Execute commands
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|||||||
@@ -463,6 +463,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -190,6 +190,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -466,6 +466,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unknown state '%s'" % state)
|
ansible_module.fail_json(msg="Unknown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -312,6 +312,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -284,6 +284,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -355,6 +355,11 @@ def process_commands(module, commands):
|
|||||||
errors = []
|
errors = []
|
||||||
exit_args = {}
|
exit_args = {}
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if module.check_mode:
|
||||||
|
return len(commands) > 0, exit_args
|
||||||
|
|
||||||
for name, command, args in commands:
|
for name, command, args in commands:
|
||||||
try:
|
try:
|
||||||
result = api_command(module, command, name, args)
|
result = api_command(module, command, name, args)
|
||||||
|
|||||||
@@ -293,6 +293,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -824,6 +824,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
||||||
|
|
||||||
# Execute commands
|
# Execute commands
|
||||||
errors = []
|
errors = []
|
||||||
for name, command, args in commands:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -182,6 +182,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -298,6 +298,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -686,6 +686,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
||||||
|
|
||||||
# Execute commands
|
# Execute commands
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|||||||
@@ -326,6 +326,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
||||||
|
|
||||||
# Execute command
|
# Execute command
|
||||||
|
|
||||||
for command, args, _suffix in commands:
|
for command, args, _suffix in commands:
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ def main():
|
|||||||
|
|
||||||
if state == "absent":
|
if state == "absent":
|
||||||
if res_find is not None:
|
if res_find is not None:
|
||||||
|
if not ansible_module.check_mode:
|
||||||
del_trust(ansible_module, realm)
|
del_trust(ansible_module, realm)
|
||||||
changed = True
|
changed = True
|
||||||
elif res_find is None:
|
elif res_find is None:
|
||||||
@@ -256,6 +257,7 @@ def main():
|
|||||||
trust_secret, base_id, range_size, range_type,
|
trust_secret, base_id, range_size, range_type,
|
||||||
two_way, external)
|
two_way, external)
|
||||||
|
|
||||||
|
if not ansible_module.check_mode:
|
||||||
add_trust(ansible_module, realm, args)
|
add_trust(ansible_module, realm, args)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
|||||||
@@ -1377,6 +1377,10 @@ def main():
|
|||||||
|
|
||||||
del user_set
|
del user_set
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
||||||
|
|
||||||
# Execute commands
|
# Execute commands
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|||||||
@@ -910,6 +910,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unknown state '%s'" % state)
|
ansible_module.fail_json(msg="Unknown state '%s'" % state)
|
||||||
|
|
||||||
|
# Check mode exit
|
||||||
|
if ansible_module.check_mode:
|
||||||
|
ansible_module.exit_json(changed=len(commands) > 0, **exit_args)
|
||||||
|
|
||||||
# Execute commands
|
# Execute commands
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|||||||
@@ -286,6 +286,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
@@ -207,6 +207,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
ansible_module.fail_json(msg="Unkown state '%s'" % state)
|
||||||
|
|
||||||
|
# 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:
|
for name, command, args in commands:
|
||||||
|
|||||||
Reference in New Issue
Block a user