summaryrefslogtreecommitdiff
path: root/test/integration/targets/argspec/library/argspec.py
blob: 1a1d288d2384ed3d92bf15fce6feab1411ea2a5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/python
# Copyright: (c) 2020, Matt Martz <matt@sivel.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule


def main():
    module = AnsibleModule(
        {
            'required': {
                'required': True,
            },
            'required_one_of_one': {},
            'required_one_of_two': {},
            'required_by_one': {},
            'required_by_two': {},
            'required_by_three': {},
            'state': {
                'type': 'str',
                'choices': ['absent', 'present'],
            },
            'path': {},
            'content': {},
            'mapping': {
                'type': 'dict',
            },
            'required_one_of': {
                'required_one_of': [['thing', 'other']],
                'type': 'list',
                'elements': 'dict',
                'options': {
                    'thing': {},
                    'other': {},
                },
            },
            'required_by': {
                'required_by': {'thing': 'other'},
                'type': 'list',
                'elements': 'dict',
                'options': {
                    'thing': {},
                    'other': {},
                },
            },
            'required_together': {
                'required_together': [['thing', 'other']],
                'type': 'list',
                'elements': 'dict',
                'options': {
                    'thing': {},
                    'other': {},
                    'another': {},
                },
            },
            'required_if': {
                'required_if': (
                    ('thing', 'foo', ('other',), True),
                ),
                'type': 'list',
                'elements': 'dict',
                'options': {
                    'thing': {},
                    'other': {},
                    'another': {},
                },
            },
            'json': {
                'type': 'json',
            },
            'fail_on_missing_params': {
                'type': 'list',
                'default': [],
            },
            'needed_param': {},
            'required_together_one': {},
            'required_together_two': {},
            'suboptions_list_no_elements': {
                'type': 'list',
                'options': {
                    'thing': {},
                },
            },
            'choices_with_strings_like_bools': {
                'type': 'str',
                'choices': [
                    'on',
                    'off',
                ],
            },
            'choices': {
                'type': 'str',
                'choices': [
                    'foo',
                    'bar',
                ],
            },
            'list_choices': {
                'type': 'list',
                'choices': [
                    'foo',
                    'bar',
                    'baz',
                ],
            },
            'primary': {
                'type': 'str',
                'aliases': [
                    'alias',
                ],
            },
            'password': {
                'type': 'str',
                'no_log': True,
            },
            'not_a_password': {
                'type': 'str',
                'no_log': False,
            },
            'maybe_password': {
                'type': 'str',
            },
            'int': {
                'type': 'int',
            },
            'apply_defaults': {
                'type': 'dict',
                'apply_defaults': True,
                'options': {
                    'foo': {
                        'type': 'str',
                    },
                    'bar': {
                        'type': 'str',
                        'default': 'baz',
                    },
                },
            },
        },
        required_if=(
            ('state', 'present', ('path', 'content'), True),
        ),
        mutually_exclusive=(
            ('path', 'content'),
        ),
        required_one_of=(
            ('required_one_of_one', 'required_one_of_two'),
        ),
        required_by={
            'required_by_one': ('required_by_two', 'required_by_three'),
        },
        required_together=(
            ('required_together_one', 'required_together_two'),
        ),
    )

    module.fail_on_missing_params(module.params['fail_on_missing_params'])

    module.exit_json(**module.params)


if __name__ == '__main__':
    main()