mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
MH decorators - added decorators for check_mode (#3849)
* MH decorators - added decorators for check_mode * added changelog fragment
This commit is contained in:
parent
d50f30c618
commit
fb79c2998e
4 changed files with 74 additions and 3 deletions
|
@ -30,30 +30,39 @@ EXAMPLES = ""
|
|||
RETURN = ""
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.deco import check_mode_skip
|
||||
|
||||
|
||||
class MSimple(ModuleHelper):
|
||||
output_params = ('a', 'b', 'c')
|
||||
module = dict(
|
||||
argument_spec=dict(
|
||||
a=dict(type='int'),
|
||||
a=dict(type='int', default=0),
|
||||
b=dict(type='str'),
|
||||
c=dict(type='str'),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
def __init_module__(self):
|
||||
self.vars.set('value', None)
|
||||
self.vars.set('abc', "abc", diff=True)
|
||||
|
||||
@check_mode_skip
|
||||
def process_a3_bc(self):
|
||||
if self.vars.a == 3:
|
||||
self.vars['b'] = str(self.vars.b) * 3
|
||||
self.vars['c'] = str(self.vars.c) * 3
|
||||
|
||||
def __run__(self):
|
||||
if (0 if self.vars.a is None else self.vars.a) >= 100:
|
||||
if self.vars.a >= 100:
|
||||
raise Exception("a >= 100")
|
||||
if self.vars.c == "abc change":
|
||||
self.vars['abc'] = "changed abc"
|
||||
if self.vars.get('a', 0) == 2:
|
||||
self.vars['b'] = str(self.vars.b) * 2
|
||||
self.vars['c'] = str(self.vars.c) * 2
|
||||
self.process_a3_bc()
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue