From 41101e55a09c618fae5ed16c005cfff64ebe5c0c Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Tue, 17 Aug 2021 20:43:18 +1200 Subject: [PATCH] module_helper - implemented classmethod to start the module (#3206) * module_helper - implemented classmethod to start the module plus minor change * rolled back the __changed__() method * added changelog fragment * Update plugins/module_utils/mh/base.py Co-authored-by: Sviatoslav Sydorenko * no capt Piccards allowed in the base class * removed extra piccards Co-authored-by: Sviatoslav Sydorenko --- changelogs/fragments/3206-mh-classmethod.yaml | 2 ++ plugins/module_utils/mh/base.py | 4 ++++ plugins/modules/packaging/language/cpanm.py | 3 +-- plugins/modules/system/xfconf.py | 3 +-- 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/3206-mh-classmethod.yaml diff --git a/changelogs/fragments/3206-mh-classmethod.yaml b/changelogs/fragments/3206-mh-classmethod.yaml new file mode 100644 index 0000000000..19cd8a6739 --- /dev/null +++ b/changelogs/fragments/3206-mh-classmethod.yaml @@ -0,0 +1,2 @@ +minor_changes: + - module_helper module_utils - added classmethod to trigger the execution of MH modules (https://github.com/ansible-collections/community.general/pull/3206). diff --git a/plugins/module_utils/mh/base.py b/plugins/module_utils/mh/base.py index a120c2556e..90c228b306 100644 --- a/plugins/module_utils/mh/base.py +++ b/plugins/module_utils/mh/base.py @@ -63,3 +63,7 @@ class ModuleHelperBase(object): if 'failed' not in output: output['failed'] = False self.module.exit_json(changed=self.has_changed(), **output) + + @classmethod + def execute(cls, module=None): + cls(module).run() diff --git a/plugins/modules/packaging/language/cpanm.py b/plugins/modules/packaging/language/cpanm.py index b8ab7e1a2f..d2c4d5a2ec 100644 --- a/plugins/modules/packaging/language/cpanm.py +++ b/plugins/modules/packaging/language/cpanm.py @@ -248,8 +248,7 @@ class CPANMinus(CmdMixin, ModuleHelper): def main(): - cpanm = CPANMinus() - cpanm.run() + CPANMinus.execute() if __name__ == '__main__': diff --git a/plugins/modules/system/xfconf.py b/plugins/modules/system/xfconf.py index 001613fc23..baf6bdd494 100644 --- a/plugins/modules/system/xfconf.py +++ b/plugins/modules/system/xfconf.py @@ -277,8 +277,7 @@ class XFConfProperty(CmdMixin, StateMixin, ModuleHelper): def main(): - xfconf = XFConfProperty() - xfconf.run() + XFConfProperty.execute() if __name__ == '__main__':