Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_user_devicegroup_dynamicmapping.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_user_devicegroup_dynamicmapping
15 short_description: Configure device groups.
16 version_added: "2.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 revision_note:
22 description: The change note that can be specified when an object is created or updated.
23 type: str
24 adom:
25 description: The parameter (adom) in requested url.
26 type: str
27 required: true
28 device-group:
29 description: Deprecated, please use "device_group"
30 type: str
31 device_group:
32 description: The parameter (device-group) in requested url.
33 type: str
34 user_devicegroup_dynamicmapping:
35 description: The top level parameters set.
36 required: false
37 type: dict
38 suboptions:
39 _if_unmanaged:
40 type: int
41 description: If unmanaged.
42 _scope:
43 type: list
44 elements: dict
45 description: Scope.
46 suboptions:
47 name:
48 type: str
49 description: Name.
50 vdom:
51 type: str
52 description: Vdom.
53 comment:
54 type: str
55 description: Comment.
56 member:
57 type: raw
58 description: (list or str) Member.
59 '''
60
61 EXAMPLES = '''
62 - name: Example playbook
63 hosts: fortimanagers
64 gather_facts: false
65 connection: httpapi
66 vars:
67 ansible_httpapi_use_ssl: true
68 ansible_httpapi_validate_certs: false
69 ansible_httpapi_port: 443
70 tasks:
71 - name: Create User Device Group
72 fortinet.fortimanager.fmgr_user_devicegroup:
73 adom: ansible
74 state: "present"
75 user_devicegroup:
76 name: ansible-test
77
78 - name: Configure dynamic mappings of device group
79 fortinet.fortimanager.fmgr_user_devicegroup_dynamicmapping:
80 bypass_validation: false
81 adom: ansible
82 device_group: ansible-test # name
83 state: present
84 user_devicegroup_dynamicmapping:
85 _if_unmanaged: 10
86 _scope:
87 - name: FGT_AWS # need a valid device name
88 vdom: root # need a valid vdom name under the device
89 comment: ansible-comment
90 member: ios-device
91
92 - name: Gathering fortimanager facts
93 hosts: fortimanagers
94 gather_facts: false
95 connection: httpapi
96 vars:
97 ansible_httpapi_use_ssl: true
98 ansible_httpapi_validate_certs: false
99 ansible_httpapi_port: 443
100 tasks:
101 - name: Retrieve all the dynamic mappings of device group
102 fortinet.fortimanager.fmgr_fact:
103 facts:
104 selector: "user_devicegroup_dynamicmapping"
105 params:
106 adom: "ansible"
107 device_group: "ansible-test" # name
108 dynamic_mapping: "your_value"
109 '''
110
111 RETURN = '''
112 meta:
113 description: The result of the request.
114 type: dict
115 returned: always
116 contains:
117 request_url:
118 description: The full url requested.
119 returned: always
120 type: str
121 sample: /sys/login/user
122 response_code:
123 description: The status of api request.
124 returned: always
125 type: int
126 sample: 0
127 response_data:
128 description: The api response.
129 type: list
130 returned: always
131 response_message:
132 description: The descriptive message of the api response.
133 type: str
134 returned: always
135 sample: OK.
136 system_information:
137 description: The information of the target system.
138 type: dict
139 returned: always
140 rc:
141 description: The status the request.
142 type: int
143 returned: always
144 sample: 0
145 version_check_warning:
146 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
147 type: list
148 returned: complex
149 '''
150 from ansible.module_utils.basic import AnsibleModule
151 from ansible.module_utils.connection import Connection
152 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
153 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
154
155
156 def main():
157 urls_list = [
158 '/pm/config/adom/{adom}/obj/user/device-group/{device-group}/dynamic_mapping',
159 '/pm/config/global/obj/user/device-group/{device-group}/dynamic_mapping'
160 ]
161 module_arg_spec = {
162 'adom': {'required': True, 'type': 'str'},
163 'device-group': {'type': 'str', 'api_name': 'device_group'},
164 'device_group': {'type': 'str'},
165 'revision_note': {'type': 'str'},
166 'user_devicegroup_dynamicmapping': {
167 'type': 'dict', 'v_range': [['6.0.0', '7.2.1']],
168 'options': {
169 '_if_unmanaged': {'v_range': [['6.0.0', '7.2.1']], 'type': 'int'},
170 '_scope': {
171 'v_range': [['6.0.0', '7.2.1']],
172 'type': 'list',
173 'options': {'name': {'v_range': [['6.0.0', '7.2.1']], 'type': 'str'}, 'vdom': {'v_range': [['6.0.0', '7.2.1']], 'type': 'str'}},
174 'elements': 'dict'
175 },
176 'comment': {'v_range': [['6.0.0', '7.2.1']], 'type': 'str'},
177 'member': {'v_range': [['6.0.0', '7.2.1']], 'type': 'raw'}
178 }
179 }
180 }
181
182 module_option_spec = get_module_arg_spec('full crud')
183 module_arg_spec.update(module_option_spec)
184 check_galaxy_version(module_arg_spec)
185 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'user_devicegroup_dynamicmapping'),
186 supports_check_mode=True)
187 if not module._socket_path:
188 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
189 connection = Connection(module._socket_path)
190 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
191 'complex:{{module}}["_scope"][0]["name"]+"/"+{{module}}["_scope"][0]["vdom"]', 'data', module, connection)
192 fmgr.process_crud()
193 module.exit_json(meta=module.params)
194
195
196 if __name__ == '__main__':
197 main()