mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ModuleHelper - deprecate attribute VarDict (#3801)
* ModuleHelper - deprecate attribute VarDict * added changelog fragment
This commit is contained in:
parent
bc619bcefc
commit
2896131ca7
5 changed files with 40 additions and 2 deletions
2
changelogs/fragments/3801-mh-deprecate-vardict-attr.yaml
Normal file
2
changelogs/fragments/3801-mh-deprecate-vardict-attr.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
deprecated_features:
|
||||||
|
- module_helper module utils - deprecated the attribute ``ModuleHelper.VarDict`` (https://github.com/ansible-collections/community.general/pull/3801).
|
|
@ -13,9 +13,10 @@ from ansible_collections.community.general.plugins.module_utils.mh.mixins.cmd im
|
||||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.state import StateMixin
|
from ansible_collections.community.general.plugins.module_utils.mh.mixins.state import StateMixin
|
||||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.deps import DependencyMixin
|
from ansible_collections.community.general.plugins.module_utils.mh.mixins.deps import DependencyMixin
|
||||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.vars import VarsMixin, VarDict as _VD
|
from ansible_collections.community.general.plugins.module_utils.mh.mixins.vars import VarsMixin, VarDict as _VD
|
||||||
|
from ansible_collections.community.general.plugins.module_utils.mh.mixins.deprecate_attrs import DeprecateAttrsMixin
|
||||||
|
|
||||||
|
|
||||||
class ModuleHelper(VarsMixin, DependencyMixin, ModuleHelperBase):
|
class ModuleHelper(DeprecateAttrsMixin, VarsMixin, DependencyMixin, ModuleHelperBase):
|
||||||
_output_conflict_list = ('msg', 'exception', 'output', 'vars', 'changed')
|
_output_conflict_list = ('msg', 'exception', 'output', 'vars', 'changed')
|
||||||
facts_name = None
|
facts_name = None
|
||||||
output_params = ()
|
output_params = ()
|
||||||
|
@ -36,6 +37,15 @@ class ModuleHelper(VarsMixin, DependencyMixin, ModuleHelperBase):
|
||||||
fact=name in self.facts_params,
|
fact=name in self.facts_params,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._deprecate_attr(
|
||||||
|
attr="VarDict",
|
||||||
|
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",
|
||||||
|
target=ModuleHelper,
|
||||||
|
module=self.module)
|
||||||
|
|
||||||
def update_output(self, **kwargs):
|
def update_output(self, **kwargs):
|
||||||
self.update_vars(meta={"output": True}, **kwargs)
|
self.update_vars(meta={"output": True}, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -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
|
from ansible_collections.community.general.plugins.module_utils.mh.mixins.deprecate_attrs import DeprecateAttrsMixin
|
||||||
|
|
||||||
|
|
||||||
class MSimpleDA(DeprecateAttrsMixin, ModuleHelper):
|
class MSimpleDA(ModuleHelper):
|
||||||
output_params = ('a',)
|
output_params = ('a',)
|
||||||
module = dict(
|
module = dict(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
|
|
|
@ -24,6 +24,10 @@ options:
|
||||||
c:
|
c:
|
||||||
description: cccc
|
description: cccc
|
||||||
type: str
|
type: str
|
||||||
|
trigger_depr_attr:
|
||||||
|
description: tries to access VarDict
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
state:
|
state:
|
||||||
description: test states
|
description: test states
|
||||||
type: str
|
type: str
|
||||||
|
@ -45,12 +49,15 @@ class MState(StateModuleHelper):
|
||||||
a=dict(type='int', required=True),
|
a=dict(type='int', required=True),
|
||||||
b=dict(type='str'),
|
b=dict(type='str'),
|
||||||
c=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'),
|
state=dict(type='str', choices=['join', 'b_x_a', 'c_x_a', 'both_x_a', 'nop'], default='join'),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init_module__(self):
|
def __init_module__(self):
|
||||||
self.vars.set('result', "abc", diff=True)
|
self.vars.set('result', "abc", diff=True)
|
||||||
|
if self.vars.trigger_depr_attr:
|
||||||
|
dummy = self.VarDict
|
||||||
|
|
||||||
def state_join(self):
|
def state_join(self):
|
||||||
self.vars['result'] = "".join([str(self.vars.a), str(self.vars.b), str(self.vars.c)])
|
self.vars['result'] = "".join([str(self.vars.a), str(self.vars.b), str(self.vars.c)])
|
||||||
|
|
|
@ -69,9 +69,25 @@
|
||||||
a: 5
|
a: 5
|
||||||
b: foo
|
b: foo
|
||||||
c: bar
|
c: bar
|
||||||
|
trigger_depr_attr: true
|
||||||
state: both_x_a
|
state: both_x_a
|
||||||
register: state5
|
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
|
- name: assert state5
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -80,3 +96,6 @@
|
||||||
- state5.c == "bar"
|
- state5.c == "bar"
|
||||||
- state5.result == "foobarfoobarfoobarfoobarfoobar"
|
- state5.result == "foobarfoobarfoobarfoobarfoobar"
|
||||||
- state5 is changed
|
- 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) }}'
|
||||||
|
|
Loading…
Reference in a new issue