Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_system_dhcp_server.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_system_dhcp_server
15 short_description: Configure DHCP servers.
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 system_dhcp_server:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 auto_configuration:
34 aliases: ['auto-configuration']
35 type: str
36 description: Enable/disable auto configuration.
37 choices: ['disable', 'enable']
38 conflicted_ip_timeout:
39 aliases: ['conflicted-ip-timeout']
40 type: int
41 description: Time in seconds to wait after a conflicted IP address is removed from the DHCP range before it can be reused.
42 ddns_auth:
43 aliases: ['ddns-auth']
44 type: str
45 description: DDNS authentication mode.
46 choices: ['disable', 'tsig']
47 ddns_key:
48 aliases: ['ddns-key']
49 type: raw
50 description: (list or str) DDNS update key
51 ddns_keyname:
52 aliases: ['ddns-keyname']
53 type: str
54 description: DDNS update key name.
55 ddns_server_ip:
56 aliases: ['ddns-server-ip']
57 type: str
58 description: DDNS server IP.
59 ddns_ttl:
60 aliases: ['ddns-ttl']
61 type: int
62 description: TTL.
63 ddns_update:
64 aliases: ['ddns-update']
65 type: str
66 description: Enable/disable DDNS update for DHCP.
67 choices: ['disable', 'enable']
68 ddns_update_override:
69 aliases: ['ddns-update-override']
70 type: str
71 description: Enable/disable DDNS update override for DHCP.
72 choices: ['disable', 'enable']
73 ddns_zone:
74 aliases: ['ddns-zone']
75 type: str
76 description: Zone of your domain name
77 default_gateway:
78 aliases: ['default-gateway']
79 type: str
80 description: Default gateway IP address assigned by the DHCP server.
81 dns_server1:
82 aliases: ['dns-server1']
83 type: str
84 description: DNS server 1.
85 dns_server2:
86 aliases: ['dns-server2']
87 type: str
88 description: DNS server 2.
89 dns_server3:
90 aliases: ['dns-server3']
91 type: str
92 description: DNS server 3.
93 dns_service:
94 aliases: ['dns-service']
95 type: str
96 description: Options for assigning DNS servers to DHCP clients.
97 choices: ['default', 'specify', 'local']
98 domain:
99 type: str
100 description: Domain name suffix for the IP addresses that the DHCP server assigns to clients.
101 exclude_range:
102 aliases: ['exclude-range']
103 type: list
104 elements: dict
105 description: Exclude range.
106 suboptions:
107 end_ip:
108 aliases: ['end-ip']
109 type: str
110 description: End of IP range.
111 id:
112 type: int
113 description: ID.
114 start_ip:
115 aliases: ['start-ip']
116 type: str
117 description: Start of IP range.
118 vci_match:
119 aliases: ['vci-match']
120 type: str
121 description: Enable/disable vendor class identifier
122 choices: ['disable', 'enable']
123 vci_string:
124 aliases: ['vci-string']
125 type: raw
126 description: (list) One or more VCI strings in quotes separated by spaces.
127 lease_time:
128 aliases: ['lease-time']
129 type: int
130 description: Lease time in seconds, 0 means default lease time.
131 uci_match:
132 aliases: ['uci-match']
133 type: str
134 description: Enable/disable user class identifier
135 choices: ['disable', 'enable']
136 uci_string:
137 aliases: ['uci-string']
138 type: raw
139 description: (list) One or more UCI strings in quotes separated by spaces.
140 filename:
141 type: str
142 description: Name of the boot file on the TFTP server.
143 forticlient_on_net_status:
144 aliases: ['forticlient-on-net-status']
145 type: str
146 description: Enable/disable FortiClient-On-Net service for this DHCP server.
147 choices: ['disable', 'enable']
148 id:
149 type: int
150 description: ID.
151 required: true
152 interface:
153 type: str
154 description: DHCP server can assign IP configurations to clients connected to this interface.
155 ip_mode:
156 aliases: ['ip-mode']
157 type: str
158 description: Method used to assign client IP.
159 choices: ['range', 'usrgrp']
160 ip_range:
161 aliases: ['ip-range']
162 type: list
163 elements: dict
164 description: Ip range.
165 suboptions:
166 end_ip:
167 aliases: ['end-ip']
168 type: str
169 description: End of IP range.
170 id:
171 type: int
172 description: ID.
173 start_ip:
174 aliases: ['start-ip']
175 type: str
176 description: Start of IP range.
177 vci_match:
178 aliases: ['vci-match']
179 type: str
180 description: Enable/disable vendor class identifier
181 choices: ['disable', 'enable']
182 vci_string:
183 aliases: ['vci-string']
184 type: raw
185 description: (list) One or more VCI strings in quotes separated by spaces.
186 lease_time:
187 aliases: ['lease-time']
188 type: int
189 description: Lease time in seconds, 0 means default lease time.
190 uci_match:
191 aliases: ['uci-match']
192 type: str
193 description: Enable/disable user class identifier
194 choices: ['disable', 'enable']
195 uci_string:
196 aliases: ['uci-string']
197 type: raw
198 description: (list) One or more UCI strings in quotes separated by spaces.
199 ipsec_lease_hold:
200 aliases: ['ipsec-lease-hold']
201 type: int
202 description: DHCP over IPsec leases expire this many seconds after tunnel down
203 lease_time:
204 aliases: ['lease-time']
205 type: int
206 description: Lease time in seconds, 0 means unlimited.
207 mac_acl_default_action:
208 aliases: ['mac-acl-default-action']
209 type: str
210 description: MAC access control default action
211 choices: ['assign', 'block']
212 netmask:
213 type: str
214 description: Netmask assigned by the DHCP server.
215 next_server:
216 aliases: ['next-server']
217 type: str
218 description: IP address of a server
219 ntp_server1:
220 aliases: ['ntp-server1']
221 type: str
222 description: NTP server 1.
223 ntp_server2:
224 aliases: ['ntp-server2']
225 type: str
226 description: NTP server 2.
227 ntp_server3:
228 aliases: ['ntp-server3']
229 type: str
230 description: NTP server 3.
231 ntp_service:
232 aliases: ['ntp-service']
233 type: str
234 description: Options for assigning Network Time Protocol
235 choices: ['default', 'specify', 'local']
236 options:
237 type: list
238 elements: dict
239 description: Options.
240 suboptions:
241 code:
242 type: int
243 description: DHCP option code.
244 id:
245 type: int
246 description: ID.
247 ip:
248 type: raw
249 description: (list) DHCP option IPs.
250 type:
251 type: str
252 description: DHCP option type.
253 choices: ['hex', 'string', 'ip', 'fqdn']
254 value:
255 type: str
256 description: DHCP option value.
257 vci_match:
258 aliases: ['vci-match']
259 type: str
260 description: Enable/disable vendor class identifier
261 choices: ['disable', 'enable']
262 vci_string:
263 aliases: ['vci-string']
264 type: raw
265 description: (list) One or more VCI strings in quotes separated by spaces.
266 uci_match:
267 aliases: ['uci-match']
268 type: str
269 description: Enable/disable user class identifier
270 choices: ['disable', 'enable']
271 uci_string:
272 aliases: ['uci-string']
273 type: raw
274 description: (list) One or more UCI strings in quotes separated by spaces.
275 reserved_address:
276 aliases: ['reserved-address']
277 type: list
278 elements: dict
279 description: Reserved address.
280 suboptions:
281 action:
282 type: str
283 description: Options for the DHCP server to configure the client with the reserved MAC address.
284 choices: ['assign', 'block', 'reserved']
285 description:
286 type: str
287 description: Description.
288 id:
289 type: int
290 description: ID.
291 ip:
292 type: str
293 description: IP address to be reserved for the MAC address.
294 mac:
295 type: str
296 description: MAC address of the client that will get the reserved IP address.
297 circuit_id:
298 aliases: ['circuit-id']
299 type: str
300 description: Option 82 circuit-ID of the client that will get the reserved IP address.
301 circuit_id_type:
302 aliases: ['circuit-id-type']
303 type: str
304 description: DHCP option type.
305 choices: ['hex', 'string']
306 remote_id:
307 aliases: ['remote-id']
308 type: str
309 description: Option 82 remote-ID of the client that will get the reserved IP address.
310 remote_id_type:
311 aliases: ['remote-id-type']
312 type: str
313 description: DHCP option type.
314 choices: ['hex', 'string']
315 type:
316 type: str
317 description: DHCP reserved-address type.
318 choices: ['mac', 'option82']
319 server_type:
320 aliases: ['server-type']
321 type: str
322 description: DHCP server can be a normal DHCP server or an IPsec DHCP server.
323 choices: ['regular', 'ipsec']
324 status:
325 type: str
326 description: Enable/disable this DHCP configuration.
327 choices: ['disable', 'enable']
328 tftp_server:
329 aliases: ['tftp-server']
330 type: raw
331 description: (list) One or more hostnames or IP addresses of the TFTP servers in quotes separated by spaces.
332 timezone:
333 type: str
334 description: Select the time zone to be assigned to DHCP clients.
335 choices: ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11',
336 '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23',
337 '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35',
338 '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47',
339 '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59',
340 '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71',
341 '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83',
342 '84', '85', '86', '87']
343 timezone_option:
344 aliases: ['timezone-option']
345 type: str
346 description: Options for the DHCP server to set the clients time zone.
347 choices: ['disable', 'default', 'specify']
348 vci_match:
349 aliases: ['vci-match']
350 type: str
351 description: Enable/disable vendor class identifier
352 choices: ['disable', 'enable']
353 vci_string:
354 aliases: ['vci-string']
355 type: raw
356 description: (list) One or more VCI strings in quotes separated by spaces.
357 wifi_ac1:
358 aliases: ['wifi-ac1']
359 type: str
360 description: WiFi Access Controller 1 IP address
361 wifi_ac2:
362 aliases: ['wifi-ac2']
363 type: str
364 description: WiFi Access Controller 2 IP address
365 wifi_ac3:
366 aliases: ['wifi-ac3']
367 type: str
368 description: WiFi Access Controller 3 IP address
369 wins_server1:
370 aliases: ['wins-server1']
371 type: str
372 description: WINS server 1.
373 wins_server2:
374 aliases: ['wins-server2']
375 type: str
376 description: WINS server 2.
377 dns_server4:
378 aliases: ['dns-server4']
379 type: str
380 description: DNS server 4.
381 wifi_ac_service:
382 aliases: ['wifi-ac-service']
383 type: str
384 description: Options for assigning WiFi Access Controllers to DHCP clients
385 choices: ['specify', 'local']
386 auto_managed_status:
387 aliases: ['auto-managed-status']
388 type: str
389 description: Enable/disable use of this DHCP server once this interface has been assigned an IP address from FortiIPAM.
390 choices: ['disable', 'enable']
391 dhcp_settings_from_fortiipam:
392 aliases: ['dhcp-settings-from-fortiipam']
393 type: str
394 description: Enable/disable populating of DHCP server settings from FortiIPAM.
395 choices: ['disable', 'enable']
396 relay_agent:
397 aliases: ['relay-agent']
398 type: str
399 description: Relay agent IP.
400 shared_subnet:
401 aliases: ['shared-subnet']
402 type: str
403 description: Enable/disable shared subnet.
404 choices: ['disable', 'enable']
405 '''
406
407 EXAMPLES = '''
408 - name: Example playbook
409 hosts: fortimanagers
410 gather_facts: false
411 connection: httpapi
412 vars:
413 ansible_httpapi_use_ssl: true
414 ansible_httpapi_validate_certs: false
415 ansible_httpapi_port: 443
416 tasks:
417 - name: Configure DHCP servers.
418 fortinet.fortimanager.fmgr_system_dhcp_server:
419 bypass_validation: false
420 adom: ansible
421 state: present
422 system_dhcp_server:
423 auto_configuration: enable # <value in [disable, enable]>
424 default_gateway: "222.222.222.1"
425 filename: ansible-file
426 id: 1
427 interface: any
428 ip_mode: range # <value in [range, usrgrp]>
429 ip_range:
430 - end_ip: 222.222.222.22
431 id: 1
432 start_ip: 222.222.222.2
433 netmask: 255.255.255.0
434 server_type: regular # <value in [regular, ipsec]>
435 status: disable # <value in [disable, enable]>
436
437 - name: Gathering fortimanager facts
438 hosts: fortimanagers
439 gather_facts: false
440 connection: httpapi
441 vars:
442 ansible_httpapi_use_ssl: true
443 ansible_httpapi_validate_certs: false
444 ansible_httpapi_port: 443
445 tasks:
446 - name: Retrieve all the DHCP servers
447 fortinet.fortimanager.fmgr_fact:
448 facts:
449 selector: "system_dhcp_server"
450 params:
451 adom: "ansible"
452 server: "your_value"
453 '''
454
455 RETURN = '''
456 meta:
457 description: The result of the request.
458 type: dict
459 returned: always
460 contains:
461 request_url:
462 description: The full url requested.
463 returned: always
464 type: str
465 sample: /sys/login/user
466 response_code:
467 description: The status of api request.
468 returned: always
469 type: int
470 sample: 0
471 response_data:
472 description: The api response.
473 type: list
474 returned: always
475 response_message:
476 description: The descriptive message of the api response.
477 type: str
478 returned: always
479 sample: OK.
480 system_information:
481 description: The information of the target system.
482 type: dict
483 returned: always
484 rc:
485 description: The status the request.
486 type: int
487 returned: always
488 sample: 0
489 version_check_warning:
490 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
491 type: list
492 returned: complex
493 '''
494 from ansible.module_utils.basic import AnsibleModule
495 from ansible.module_utils.connection import Connection
496 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
497 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
498
499
500 def main():
501 urls_list = [
502 '/pm/config/adom/{adom}/obj/system/dhcp/server',
503 '/pm/config/global/obj/system/dhcp/server'
504 ]
505 module_arg_spec = {
506 'adom': {'required': True, 'type': 'str'},
507 'revision_note': {'type': 'str'},
508 'system_dhcp_server': {
509 'type': 'dict', 'v_range': [['6.0.0', '']],
510 'options': {
511 'auto-configuration': {'choices': ['disable', 'enable'], 'type': 'str'},
512 'conflicted-ip-timeout': {'type': 'int'},
513 'ddns-auth': {'choices': ['disable', 'tsig'], 'type': 'str'},
514 'ddns-key': {'no_log': True, 'type': 'raw'},
515 'ddns-keyname': {'no_log': True, 'type': 'str'},
516 'ddns-server-ip': {'type': 'str'},
517 'ddns-ttl': {'type': 'int'},
518 'ddns-update': {'choices': ['disable', 'enable'], 'type': 'str'},
519 'ddns-update-override': {'choices': ['disable', 'enable'], 'type': 'str'},
520 'ddns-zone': {'type': 'str'},
521 'default-gateway': {'type': 'str'},
522 'dns-server1': {'type': 'str'},
523 'dns-server2': {'type': 'str'},
524 'dns-server3': {'type': 'str'},
525 'dns-service': {'choices': ['default', 'specify', 'local'], 'type': 'str'},
526 'domain': {'type': 'str'},
527 'exclude-range': {
528 'type': 'list',
529 'options': {
530 'end-ip': {'type': 'str'},
531 'id': {'type': 'int'},
532 'start-ip': {'type': 'str'},
533 'vci-match': {'v_range': [['7.2.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
534 'vci-string': {'v_range': [['7.2.1', '']], 'type': 'raw'},
535 'lease-time': {'v_range': [['7.2.2', '']], 'type': 'int'},
536 'uci-match': {'v_range': [['7.2.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
537 'uci-string': {'v_range': [['7.2.2', '']], 'type': 'raw'}
538 },
539 'elements': 'dict'
540 },
541 'filename': {'type': 'str'},
542 'forticlient-on-net-status': {'choices': ['disable', 'enable'], 'type': 'str'},
543 'id': {'required': True, 'type': 'int'},
544 'interface': {'type': 'str'},
545 'ip-mode': {'choices': ['range', 'usrgrp'], 'type': 'str'},
546 'ip-range': {
547 'type': 'list',
548 'options': {
549 'end-ip': {'type': 'str'},
550 'id': {'type': 'int'},
551 'start-ip': {'type': 'str'},
552 'vci-match': {'v_range': [['7.2.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
553 'vci-string': {'v_range': [['7.2.1', '']], 'type': 'raw'},
554 'lease-time': {'v_range': [['7.2.2', '']], 'type': 'int'},
555 'uci-match': {'v_range': [['7.2.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
556 'uci-string': {'v_range': [['7.2.2', '']], 'type': 'raw'}
557 },
558 'elements': 'dict'
559 },
560 'ipsec-lease-hold': {'type': 'int'},
561 'lease-time': {'type': 'int'},
562 'mac-acl-default-action': {'choices': ['assign', 'block'], 'type': 'str'},
563 'netmask': {'type': 'str'},
564 'next-server': {'type': 'str'},
565 'ntp-server1': {'type': 'str'},
566 'ntp-server2': {'type': 'str'},
567 'ntp-server3': {'type': 'str'},
568 'ntp-service': {'choices': ['default', 'specify', 'local'], 'type': 'str'},
569 'options': {
570 'type': 'list',
571 'options': {
572 'code': {'type': 'int'},
573 'id': {'type': 'int'},
574 'ip': {'type': 'raw'},
575 'type': {'choices': ['hex', 'string', 'ip', 'fqdn'], 'type': 'str'},
576 'value': {'type': 'str'},
577 'vci-match': {'v_range': [['7.2.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
578 'vci-string': {'v_range': [['7.2.1', '']], 'type': 'raw'},
579 'uci-match': {'v_range': [['7.2.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
580 'uci-string': {'v_range': [['7.2.2', '']], 'type': 'raw'}
581 },
582 'elements': 'dict'
583 },
584 'reserved-address': {
585 'type': 'list',
586 'options': {
587 'action': {'choices': ['assign', 'block', 'reserved'], 'type': 'str'},
588 'description': {'type': 'str'},
589 'id': {'type': 'int'},
590 'ip': {'type': 'str'},
591 'mac': {'type': 'str'},
592 'circuit-id': {'v_range': [['6.2.0', '']], 'type': 'str'},
593 'circuit-id-type': {'v_range': [['6.2.0', '']], 'choices': ['hex', 'string'], 'type': 'str'},
594 'remote-id': {'v_range': [['6.2.0', '']], 'type': 'str'},
595 'remote-id-type': {'v_range': [['6.2.0', '']], 'choices': ['hex', 'string'], 'type': 'str'},
596 'type': {'v_range': [['6.2.0', '']], 'choices': ['mac', 'option82'], 'type': 'str'}
597 },
598 'elements': 'dict'
599 },
600 'server-type': {'choices': ['regular', 'ipsec'], 'type': 'str'},
601 'status': {'choices': ['disable', 'enable'], 'type': 'str'},
602 'tftp-server': {'type': 'raw'},
603 'timezone': {
604 'choices': [
605 '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
606 '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41',
607 '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62',
608 '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83',
609 '84', '85', '86', '87'
610 ],
611 'type': 'str'
612 },
613 'timezone-option': {'choices': ['disable', 'default', 'specify'], 'type': 'str'},
614 'vci-match': {'choices': ['disable', 'enable'], 'type': 'str'},
615 'vci-string': {'type': 'raw'},
616 'wifi-ac1': {'type': 'str'},
617 'wifi-ac2': {'type': 'str'},
618 'wifi-ac3': {'type': 'str'},
619 'wins-server1': {'type': 'str'},
620 'wins-server2': {'type': 'str'},
621 'dns-server4': {'v_range': [['6.2.2', '']], 'type': 'str'},
622 'wifi-ac-service': {'v_range': [['6.2.2', '']], 'choices': ['specify', 'local'], 'type': 'str'},
623 'auto-managed-status': {'v_range': [['6.4.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
624 'dhcp-settings-from-fortiipam': {'v_range': [['6.4.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
625 'relay-agent': {'v_range': [['7.4.0', '']], 'type': 'str'},
626 'shared-subnet': {'v_range': [['7.4.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}
627 }
628 }
629 }
630
631 module_option_spec = get_module_arg_spec('full crud')
632 module_arg_spec.update(module_option_spec)
633 check_galaxy_version(module_arg_spec)
634 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'system_dhcp_server'),
635 supports_check_mode=True)
636 if not module._socket_path:
637 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
638 connection = Connection(module._socket_path)
639 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
640 'id', 'data', module, connection)
641 fmgr.process_crud()
642 module.exit_json(meta=module.params)
643
644
645 if __name__ == '__main__':
646 main()