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 e8aed0a759..ddca733c09 100644 --- a/plugins/modules/system/xfconf.py +++ b/plugins/modules/system/xfconf.py @@ -272,8 +272,7 @@ class XFConfProperty(CmdMixin, StateMixin, ModuleHelper): def main(): - xfconf = XFConfProperty() - xfconf.run() + XFConfProperty.execute() if __name__ == '__main__':