[PR #9577/7fa859a3 backport][stable-10] module helper: delegate debug() to AnsibleModule (#9591)

module helper: delegate debug() to AnsibleModule (#9577)

* module helper: delegate debug() to AnsibleModule

* add changelog frag

* add comments for future

* use deprecate()

* fix errors

(cherry picked from commit 7fa859a3b8)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2025-01-20 20:03:59 +01:00 committed by GitHub
parent fed5965518
commit c394fbe8e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 0 deletions

View file

@ -15,6 +15,7 @@ from ansible_collections.community.general.plugins.module_utils.mh.deco import m
class ModuleHelperBase(object):
module = None
ModuleHelperException = _MHE
# in 12.0.0 add 'debug' to the tuple
_delegated_to_module = (
'check_mode', 'get_bin_path', 'warn', 'deprecate',
)
@ -28,6 +29,18 @@ class ModuleHelperBase(object):
if not isinstance(self.module, AnsibleModule):
self.module = AnsibleModule(**self.module)
# in 12.0.0 remove this if statement entirely
if hasattr(self, 'debug'):
msg = (
"This class ({cls}) has an attribute 'debug' defined and that is deprecated. "
"Method 'debug' will be an integral part of ModuleHelper in community.general "
"12.0.0, delegated to the underlying AnsibleModule object. "
"Please rename the existing attribute to prevent this message from showing.".format(cls=self.__class__.__name__)
)
self.deprecate(msg, version="12.0.0", collection_name="community.general")
else:
self._delegated_to_module = self._delegated_to_module + ('debug',)
@property
def diff_mode(self):
return self.module._diff