2021-04-05 15:19:13 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-08-08 15:19:46 +02:00
|
|
|
# Copyright (c) 2021, Alexei Znamensky <russoz@gmail.com>
|
2021-04-05 15:19:13 +02:00
|
|
|
#
|
2022-08-05 13:17:19 +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: msimple
|
|
|
|
author: "Alexei Znamensky (@russoz)"
|
|
|
|
short_description: Simple module for testing
|
|
|
|
description:
|
|
|
|
- Simple module test description.
|
|
|
|
options:
|
|
|
|
a:
|
|
|
|
description: aaaa
|
|
|
|
type: int
|
|
|
|
b:
|
|
|
|
description: bbbb
|
|
|
|
type: str
|
|
|
|
c:
|
|
|
|
description: cccc
|
|
|
|
type: str
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = ""
|
|
|
|
|
|
|
|
RETURN = ""
|
|
|
|
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
|
2021-12-05 21:47:51 +01:00
|
|
|
from ansible_collections.community.general.plugins.module_utils.mh.deco import check_mode_skip
|
2021-04-05 15:19:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MSimple(ModuleHelper):
|
2023-01-04 21:40:53 +01:00
|
|
|
output_params = ('a', 'b', 'c', 'm')
|
2021-04-05 15:19:13 +02:00
|
|
|
module = dict(
|
|
|
|
argument_spec=dict(
|
2021-12-05 21:47:51 +01:00
|
|
|
a=dict(type='int', default=0),
|
2021-04-05 15:19:13 +02:00
|
|
|
b=dict(type='str'),
|
|
|
|
c=dict(type='str'),
|
2023-01-04 21:40:53 +01:00
|
|
|
m=dict(type='str'),
|
2021-04-05 15:19:13 +02:00
|
|
|
),
|
2021-12-05 21:47:51 +01:00
|
|
|
supports_check_mode=True,
|
2021-04-05 15:19:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init_module__(self):
|
|
|
|
self.vars.set('value', None)
|
|
|
|
self.vars.set('abc', "abc", diff=True)
|
|
|
|
|
2021-12-05 21:47:51 +01:00
|
|
|
@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
|
|
|
|
|
2021-04-05 15:19:13 +02:00
|
|
|
def __run__(self):
|
2021-12-05 21:47:51 +01:00
|
|
|
if self.vars.a >= 100:
|
2021-04-05 15:19:13 +02:00
|
|
|
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
|
2021-12-05 21:47:51 +01:00
|
|
|
self.process_a3_bc()
|
2021-04-05 15:19:13 +02:00
|
|
|
|
2023-01-04 21:40:53 +01:00
|
|
|
if self.vars.m:
|
|
|
|
self.vars.msg = self.vars.m
|
|
|
|
|
2021-04-05 15:19:13 +02:00
|
|
|
|
|
|
|
def main():
|
|
|
|
msimple = MSimple()
|
|
|
|
msimple.run()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|