ModuleHelper - deprecate attribute VarDict (#3801)

* ModuleHelper - deprecate attribute VarDict

* added changelog fragment
This commit is contained in:
Alexei Znamensky 2021-11-30 19:10:48 +13:00 committed by GitHub
commit 2896131ca7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 2 deletions

View file

@ -28,7 +28,7 @@ from ansible_collections.community.general.plugins.module_utils.module_helper im
from ansible_collections.community.general.plugins.module_utils.mh.mixins.deprecate_attrs import DeprecateAttrsMixin
class MSimpleDA(DeprecateAttrsMixin, ModuleHelper):
class MSimpleDA(ModuleHelper):
output_params = ('a',)
module = dict(
argument_spec=dict(

View file

@ -24,6 +24,10 @@ options:
c:
description: cccc
type: str
trigger_depr_attr:
description: tries to access VarDict
type: bool
default: false
state:
description: test states
type: str
@ -45,12 +49,15 @@ class MState(StateModuleHelper):
a=dict(type='int', required=True),
b=dict(type='str'),
c=dict(type='str'),
trigger_depr_attr=dict(type='bool', default=False),
state=dict(type='str', choices=['join', 'b_x_a', 'c_x_a', 'both_x_a', 'nop'], default='join'),
),
)
def __init_module__(self):
self.vars.set('result', "abc", diff=True)
if self.vars.trigger_depr_attr:
dummy = self.VarDict
def state_join(self):
self.vars['result'] = "".join([str(self.vars.a), str(self.vars.b), str(self.vars.c)])

View file

@ -69,9 +69,25 @@
a: 5
b: foo
c: bar
trigger_depr_attr: true
state: both_x_a
register: state5
- ansible.builtin.set_fact:
vardict_gt29:
msg: >-
ModuleHelper.VarDict attribute is deprecated, use VarDict from the
ansible_collections.community.general.plugins.module_utils.mh.mixins.vars
module instead
version: 6.0.0
collection_name: community.general
vardict_29:
msg: >-
ModuleHelper.VarDict attribute is deprecated, use VarDict from the
ansible_collections.community.general.plugins.module_utils.mh.mixins.vars
module instead
version: 6.0.0
- name: assert state5
assert:
that:
@ -80,3 +96,6 @@
- state5.c == "bar"
- state5.result == "foobarfoobarfoobarfoobarfoobar"
- state5 is changed
- vardict_depr in state5.deprecations
vars:
vardict_depr: '{{ (ansible_version.major == 2 and ansible_version.minor == 9) | ternary(vardict_29, vardict_gt29) }}'