Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_user_device.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_device
15 short_description: Configure devices.
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 user_device:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 alias:
34 type: str
35 description: Device alias.
36 required: true
37 avatar:
38 type: str
39 description: Image file for avatar
40 category:
41 type: str
42 description: Device category.
43 choices: ['none', 'android-device', 'blackberry-device', 'fortinet-device',
44 'ios-device', 'windows-device', 'amazon-device']
45 comment:
46 type: str
47 description: Comment.
48 dynamic_mapping:
49 type: list
50 elements: dict
51 description: Dynamic mapping.
52 suboptions:
53 _scope:
54 type: list
55 elements: dict
56 description: Scope.
57 suboptions:
58 name:
59 type: str
60 description: Name.
61 vdom:
62 type: str
63 description: Vdom.
64 avatar:
65 type: str
66 description: Avatar.
67 category:
68 type: str
69 description: Category.
70 choices: ['none', 'android-device', 'blackberry-device',
71 'fortinet-device', 'ios-device', 'windows-device',
72 'amazon-device']
73 comment:
74 type: str
75 description: Comment.
76 mac:
77 type: str
78 description: Mac.
79 master_device:
80 aliases: ['master-device']
81 type: str
82 description: Master device.
83 tags:
84 type: raw
85 description: (list or str) Tags.
86 type:
87 type: str
88 description: Type.
89 choices: ['ipad', 'iphone', 'gaming-console', 'blackberry-phone',
90 'blackberry-playbook', 'linux-pc', 'mac', 'windows-pc',
91 'android-phone', 'android-tablet', 'media-streaming',
92 'windows-phone', 'fortinet-device', 'ip-phone',
93 'router-nat-device', 'other-network-device', 'windows-tablet',
94 'printer', 'forticam', 'fortifone', 'unknown']
95 user:
96 type: str
97 description: User.
98 family:
99 type: str
100 description: Family.
101 hardware_vendor:
102 aliases: ['hardware-vendor']
103 type: str
104 description: Hardware vendor.
105 hardware_version:
106 aliases: ['hardware-version']
107 type: str
108 description: Hardware version.
109 os:
110 type: str
111 description: Os.
112 software_version:
113 aliases: ['software-version']
114 type: str
115 description: Software version.
116 mac:
117 type: str
118 description: Device MAC address
119 master_device:
120 aliases: ['master-device']
121 type: str
122 description: Master device
123 tagging:
124 type: list
125 elements: dict
126 description: Tagging.
127 suboptions:
128 category:
129 type: str
130 description: Tag category.
131 name:
132 type: str
133 description: Tagging entry name.
134 tags:
135 type: raw
136 description: (list) Tags.
137 type:
138 type: str
139 description: Device type.
140 choices: ['ipad', 'iphone', 'gaming-console', 'blackberry-phone',
141 'blackberry-playbook', 'linux-pc', 'mac', 'windows-pc', 'android-phone',
142 'android-tablet', 'media-streaming', 'windows-phone', 'fortinet-device',
143 'ip-phone', 'router-nat-device', 'other-network-device',
144 'windows-tablet', 'printer', 'forticam', 'fortifone', 'unknown']
145 user:
146 type: str
147 description: User name.
148 tags:
149 type: str
150 description: Applied object tags.
151 '''
152
153 EXAMPLES = '''
154 - name: Example playbook
155 hosts: fortimanagers
156 gather_facts: false
157 connection: httpapi
158 vars:
159 ansible_httpapi_use_ssl: true
160 ansible_httpapi_validate_certs: false
161 ansible_httpapi_port: 443
162 tasks:
163 - name: Configure devices.
164 fortinet.fortimanager.fmgr_user_device:
165 bypass_validation: false
166 adom: ansible
167 state: present
168 user_device:
169 alias: ansible-test-device
170 category: android-device # <value in [none, android-device, blackberry-device, ...]>
171 comment: ansible-comment
172 mac: "00:11:22:33:44:55"
173 type: iphone # <value in [ipad, iphone, gaming-console, ...]>
174
175 - name: Gathering fortimanager facts
176 hosts: fortimanagers
177 gather_facts: false
178 connection: httpapi
179 vars:
180 ansible_httpapi_use_ssl: true
181 ansible_httpapi_validate_certs: false
182 ansible_httpapi_port: 443
183 tasks:
184 - name: Retrieve all the devices
185 fortinet.fortimanager.fmgr_fact:
186 facts:
187 selector: "user_device"
188 params:
189 adom: "ansible"
190 device: "your_value"
191 '''
192
193 RETURN = '''
194 meta:
195 description: The result of the request.
196 type: dict
197 returned: always
198 contains:
199 request_url:
200 description: The full url requested.
201 returned: always
202 type: str
203 sample: /sys/login/user
204 response_code:
205 description: The status of api request.
206 returned: always
207 type: int
208 sample: 0
209 response_data:
210 description: The api response.
211 type: list
212 returned: always
213 response_message:
214 description: The descriptive message of the api response.
215 type: str
216 returned: always
217 sample: OK.
218 system_information:
219 description: The information of the target system.
220 type: dict
221 returned: always
222 rc:
223 description: The status the request.
224 type: int
225 returned: always
226 sample: 0
227 version_check_warning:
228 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
229 type: list
230 returned: complex
231 '''
232 from ansible.module_utils.basic import AnsibleModule
233 from ansible.module_utils.connection import Connection
234 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
235 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
236
237
238 def main():
239 urls_list = [
240 '/pm/config/adom/{adom}/obj/user/device',
241 '/pm/config/global/obj/user/device'
242 ]
243 module_arg_spec = {
244 'adom': {'required': True, 'type': 'str'},
245 'revision_note': {'type': 'str'},
246 'user_device': {
247 'type': 'dict', 'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']],
248 'options': {
249 'alias': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'required': True, 'type': 'str'},
250 'avatar': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
251 'category': {
252 'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']],
253 'choices': ['none', 'android-device', 'blackberry-device', 'fortinet-device', 'ios-device', 'windows-device', 'amazon-device'],
254 'type': 'str'
255 },
256 'comment': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
257 'dynamic_mapping': {
258 'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']],
259 'type': 'list',
260 'options': {
261 '_scope': {
262 'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']],
263 'type': 'list',
264 'options': {
265 'name': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
266 'vdom': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'}
267 },
268 'elements': 'dict'
269 },
270 'avatar': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
271 'category': {
272 'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']],
273 'choices': ['none', 'android-device', 'blackberry-device', 'fortinet-device', 'ios-device', 'windows-device', 'amazon-device'],
274 'type': 'str'
275 },
276 'comment': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
277 'mac': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
278 'master-device': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
279 'tags': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'raw'},
280 'type': {
281 'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']],
282 'choices': [
283 'ipad', 'iphone', 'gaming-console', 'blackberry-phone', 'blackberry-playbook', 'linux-pc', 'mac', 'windows-pc',
284 'android-phone', 'android-tablet', 'media-streaming', 'windows-phone', 'fortinet-device', 'ip-phone',
285 'router-nat-device', 'other-network-device', 'windows-tablet', 'printer', 'forticam', 'fortifone', 'unknown'
286 ],
287 'type': 'str'
288 },
289 'user': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
290 'family': {'v_range': [['6.2.1', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
291 'hardware-vendor': {'v_range': [['6.2.1', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
292 'hardware-version': {'v_range': [['6.2.1', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
293 'os': {'v_range': [['6.2.1', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
294 'software-version': {'v_range': [['6.2.1', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'}
295 },
296 'elements': 'dict'
297 },
298 'mac': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
299 'master-device': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
300 'tagging': {
301 'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']],
302 'type': 'list',
303 'options': {
304 'category': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
305 'name': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
306 'tags': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'raw'}
307 },
308 'elements': 'dict'
309 },
310 'type': {
311 'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']],
312 'choices': [
313 'ipad', 'iphone', 'gaming-console', 'blackberry-phone', 'blackberry-playbook', 'linux-pc', 'mac', 'windows-pc', 'android-phone',
314 'android-tablet', 'media-streaming', 'windows-phone', 'fortinet-device', 'ip-phone', 'router-nat-device', 'other-network-device',
315 'windows-tablet', 'printer', 'forticam', 'fortifone', 'unknown'
316 ],
317 'type': 'str'
318 },
319 'user': {'v_range': [['6.0.0', '7.2.5'], ['7.4.0', '7.4.2']], 'type': 'str'},
320 'tags': {'v_range': [['6.2.0', '6.4.15']], 'type': 'str'}
321 }
322 }
323 }
324
325 module_option_spec = get_module_arg_spec('full crud')
326 module_arg_spec.update(module_option_spec)
327 check_galaxy_version(module_arg_spec)
328 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'user_device'),
329 supports_check_mode=True)
330 if not module._socket_path:
331 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
332 connection = Connection(module._socket_path)
333 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
334 'alias', 'data', module, connection)
335 fmgr.process_crud()
336 module.exit_json(meta=module.params)
337
338
339 if __name__ == '__main__':
340 main()