mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-30 03:14:42 +00:00
sudorule: 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:
@@ -824,36 +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 = []
|
changed = ansible_module.execute_ipa_commands(
|
||||||
for name, command, args in commands:
|
commands, fail_on_member_errors=True)
|
||||||
try:
|
|
||||||
result = ansible_module.ipa_command(command, name, args)
|
|
||||||
|
|
||||||
if "completed" in result:
|
|
||||||
if result["completed"] > 0:
|
|
||||||
changed = True
|
|
||||||
else:
|
|
||||||
changed = True
|
|
||||||
except Exception as ex:
|
|
||||||
ansible_module.fail_json(msg="%s: %s: %s" % (command, name,
|
|
||||||
str(ex)))
|
|
||||||
# Get all errors
|
|
||||||
# result are ignored. All others are reported.
|
|
||||||
if "failed" in result and len(result["failed"]) > 0:
|
|
||||||
for item in result["failed"]:
|
|
||||||
failed_item = result["failed"][item]
|
|
||||||
for member_type in failed_item:
|
|
||||||
for member, failure in failed_item[member_type]:
|
|
||||||
errors.append("%s: %s %s: %s" % (
|
|
||||||
command, member_type, member, failure))
|
|
||||||
if len(errors) > 0:
|
|
||||||
ansible_module.fail_json(msg=", ".join(errors))
|
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user