the modules use the same function _exec. We could move it (and other shared things if exist), to plugins/module_utils/something.py, document it there, and use everything instead of having the code duplicated.
Move the code to a library under plugins/module_utils
It could be a parental class but i personally prefer composition.
Or it could be just a function, say, rabbitmqctl_exec (obj, args, force_exec_in_check_mode=False) where obj is an argument via which the objects will pass themselves.
the class could look like:
class RabbitMQ():
"""Doc explaining purpose, args, etc."""
def __init__(self, obj):
self. obj = obj
def exec(self, args, force_exec_in_check_mode=False):
"""Doc explaining purpose, args, etc."""
if not self.obj.module.check_mode or (self.obj.module.check_mode and force_exec_in_check_mode):
cmd = [self.obj._rabbitmqctl, '-q', '-n', self.obj.node]
rc, out, err = self.obj.module.run_command(cmd + args, check_rc=True)
return out.splitlines()
return list()
in the target classes you're changing here in __init__ we could initialize `self.rabbitmq = RabbitMQ(self)
SUMMARY
Relates https://github.com/ansible-collections/community.rabbitmq/pull/89#issuecomment-887398334
the modules use the same function
_exec
. We could move it (and other shared things if exist), toplugins/module_utils/something.py
, document it there, and use everything instead of having the code duplicated.plugins/module_utils
rabbitmqctl_exec (obj, args, force_exec_in_check_mode=False)
whereobj
is an argument via which the objects will pass themselves.the class could look like:
in the target classes you're changing here in
__init__
we could initialize `self.rabbitmq = RabbitMQ(self)and then
_exec()
method could look like:ISSUE TYPE
COMPONENT NAME
Many modules