mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-05-08 22:34:26 +00:00
Added support for client defined result data in FReeIPABaseModule
Modified support for processing result of IPA API commands so that client code can define its own processing and add return values to self.exit_args based on command result. If a subclass need to process the result of IPA API commands it should override the method `process_command_result`. The default implementation will simply evaluate if `changed` should be true.
This commit is contained in:
@@ -619,7 +619,7 @@ class FreeIPABaseModule(AnsibleModule):
|
||||
if exc_val:
|
||||
self.fail_json(msg=str(exc_val))
|
||||
|
||||
self.exit_json(changed=self.changed, user=self.exit_args)
|
||||
self.exit_json(changed=self.changed, **self.exit_args)
|
||||
|
||||
def get_command_errors(self, command, result):
|
||||
"""Look for erros into command results."""
|
||||
@@ -658,14 +658,22 @@ class FreeIPABaseModule(AnsibleModule):
|
||||
except Exception as excpt:
|
||||
self.fail_json(msg="%s: %s: %s" % (command, name, str(excpt)))
|
||||
else:
|
||||
if "completed" in result:
|
||||
if result["completed"] > 0:
|
||||
self.changed = True
|
||||
else:
|
||||
self.changed = True
|
||||
|
||||
self.process_command_result(name, command, args, result)
|
||||
self.get_command_errors(command, result)
|
||||
|
||||
def process_command_result(self, name, command, args, result):
|
||||
"""
|
||||
Process an API command result.
|
||||
|
||||
This method can be overriden in subclasses, and change self.exit_values
|
||||
to return data in the result for the controller.
|
||||
"""
|
||||
if "completed" in result:
|
||||
if result["completed"] > 0:
|
||||
self.changed = True
|
||||
else:
|
||||
self.changed = True
|
||||
|
||||
def require_ipa_attrs_change(self, command_args, ipa_attrs):
|
||||
"""
|
||||
Compare given args with current object attributes.
|
||||
|
||||
Reference in New Issue
Block a user