2021-04-05 15:19:13 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# (c) 2021, Alexei Znamensky <russoz@gmail.com>
|
|
|
|
#
|
2022-08-05 12:28:29 +02:00
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2021-04-05 15:19:13 +02:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
module: mstate
|
|
|
|
author: "Alexei Znamensky (@russoz)"
|
|
|
|
short_description: State-based module for testing
|
|
|
|
description:
|
|
|
|
- State-based module test description.
|
|
|
|
options:
|
|
|
|
a:
|
|
|
|
description: aaaa
|
|
|
|
type: int
|
|
|
|
required: yes
|
|
|
|
b:
|
|
|
|
description: bbbb
|
|
|
|
type: str
|
|
|
|
c:
|
|
|
|
description: cccc
|
|
|
|
type: str
|
2021-11-30 07:10:48 +01:00
|
|
|
trigger_depr_attr:
|
|
|
|
description: tries to access VarDict
|
|
|
|
type: bool
|
|
|
|
default: false
|
2021-04-05 15:19:13 +02:00
|
|
|
state:
|
|
|
|
description: test states
|
|
|
|
type: str
|
|
|
|
choices: [join, b_x_a, c_x_a, both_x_a]
|
|
|
|
default: join
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = ""
|
|
|
|
|
|
|
|
RETURN = ""
|
|
|
|
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
|
|
|
|
|
|
|
|
|
|
|
class MState(StateModuleHelper):
|
|
|
|
output_params = ('a', 'b', 'c', 'state')
|
|
|
|
module = dict(
|
|
|
|
argument_spec=dict(
|
|
|
|
a=dict(type='int', required=True),
|
|
|
|
b=dict(type='str'),
|
|
|
|
c=dict(type='str'),
|
2021-11-30 07:10:48 +01:00
|
|
|
trigger_depr_attr=dict(type='bool', default=False),
|
2021-04-05 15:19:13 +02:00
|
|
|
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)
|
2021-11-30 07:10:48 +01:00
|
|
|
if self.vars.trigger_depr_attr:
|
|
|
|
dummy = self.VarDict
|
2021-04-05 15:19:13 +02:00
|
|
|
|
|
|
|
def state_join(self):
|
|
|
|
self.vars['result'] = "".join([str(self.vars.a), str(self.vars.b), str(self.vars.c)])
|
|
|
|
|
|
|
|
def state_b_x_a(self):
|
|
|
|
self.vars['result'] = str(self.vars.b) * self.vars.a
|
|
|
|
|
|
|
|
def state_c_x_a(self):
|
|
|
|
self.vars['result'] = str(self.vars.c) * self.vars.a
|
|
|
|
|
|
|
|
def state_both_x_a(self):
|
|
|
|
self.vars['result'] = (str(self.vars.b) + str(self.vars.c)) * self.vars.a
|
|
|
|
|
|
|
|
def state_nop(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
mstate = MState()
|
|
|
|
mstate.run()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|