Debian Codegraph @

ansible_collections/cisco/nxos/plugins/modules/nxos_ntp_global.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2021 Red Hat
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for nxos_ntp_global
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: nxos_ntp_global
18 short_description: NTP Global resource module.
19 description:
20 - This module manages ntp configuration on devices running Cisco NX-OS.
21 version_added: 2.6.0
22 notes:
23 - Tested against NX-OS 9.3.6 on Cisco Nexus Switches.
24 - This module works with connection C(network_cli) and C(httpapi).
25 - Tested against Cisco MDS NX-OS 9.2(2) with connection C(network_cli).
26 author: Nilashish Chakraborty (@NilashishC)
27 options:
28 running_config:
29 description:
30 - This option is used only with state I(parsed).
31 - The value of this option should be the output received from the NX-OS device
32 by executing the command B(show running-config ntp).
33 - The state I(parsed) reads the configuration from C(running_config) option and
34 transforms it into Ansible structured data as per the resource module's argspec
35 and the value is then returned in the I(parsed) key within the result.
36 type: str
37 config:
38 description: A dict of ntp configuration.
39 type: dict
40 suboptions:
41 access_group:
42 description:
43 - NTP access-group.
44 - This option is unsupported on MDS switches.
45 type: dict
46 suboptions:
47 match_all:
48 description: Scan ACLs present in all ntp access groups.
49 type: bool
50 peer:
51 description: Access-group peer.
52 type: list
53 elements: dict
54 suboptions:
55 access_list:
56 description: Name of access list.
57 type: str
58 query_only:
59 description: Access-group query-only.
60 type: list
61 elements: dict
62 suboptions:
63 access_list:
64 description: Name of access list.
65 type: str
66 serve:
67 description: Access-group serve.
68 type: list
69 elements: dict
70 suboptions:
71 access_list:
72 description: Name of access list.
73 type: str
74 serve_only:
75 description: Access-group serve-only.
76 type: list
77 elements: dict
78 suboptions:
79 access_list:
80 description: Name of access list.
81 type: str
82 allow:
83 description: Enable/Disable the packets.
84 type: dict
85 suboptions:
86 control:
87 description: Control mode packets.
88 type: dict
89 suboptions:
90 rate_limit:
91 description: Rate-limit delay.
92 type: int
93 private:
94 description: Enable/Disable Private mode packets.
95 type: bool
96 authenticate:
97 description: Enable/Disable authentication.
98 type: bool
99 authentication_keys:
100 description: NTP authentication key.
101 type: list
102 elements: dict
103 suboptions:
104 id:
105 description: Authentication key number (range 1-65535).
106 type: int
107 key:
108 description: Authentication key.
109 type: str
110 encryption:
111 description:
112 - 0 for Clear text
113 - 7 for Encrypted
114 type: int
115 logging:
116 description: Enable/Disable logging of NTPD Events.
117 type: bool
118 master:
119 description:
120 - Act as NTP master clock.
121 - This option is unsupported on MDS switches.
122 type: dict
123 suboptions:
124 stratum:
125 description: Stratum number.
126 type: int
127 passive:
128 description:
129 - NTP passive command.
130 - This option is unsupported on MDS switches.
131 type: bool
132 peers:
133 description: NTP Peers.
134 type: list
135 elements: dict
136 suboptions:
137 peer:
138 description: Hostname/IP address of the NTP Peer.
139 type: str
140 key_id:
141 description: Keyid to be used while communicating to this server.
142 type: int
143 maxpoll:
144 description:
145 - Maximum interval to poll a peer.
146 - Poll interval in secs to a power of 2.
147 type: int
148 minpoll:
149 description:
150 - Minimum interval to poll a peer.
151 - Poll interval in secs to a power of 2.
152 type: int
153 prefer:
154 description:
155 - Preferred Server.
156 type: bool
157 vrf:
158 description:
159 - Display per-VRF information.
160 - This option is unsupported on MDS switches.
161 type: str
162 aliases: ["use_vrf"]
163 servers:
164 description: NTP servers.
165 type: list
166 elements: dict
167 suboptions:
168 server:
169 description: Hostname/IP address of the NTP Peer.
170 type: str
171 key_id:
172 description: Keyid to be used while communicating to this server.
173 type: int
174 maxpoll:
175 description:
176 - Maximum interval to poll a peer.
177 - Poll interval in secs to a power of 2.
178 type: int
179 minpoll:
180 description:
181 - Minimum interval to poll a peer.
182 - Poll interval in secs to a power of 2.
183 type: int
184 prefer:
185 description:
186 - Preferred Server.
187 type: bool
188 vrf:
189 description:
190 - Display per-VRF information.
191 - This option is not applicable for MDS switches.
192 type: str
193 aliases: ["use_vrf"]
194 source:
195 description:
196 - Source of NTP packets.
197 - This option is unsupported on MDS switches.
198 type: str
199 source_interface:
200 description: Source interface sending NTP packets.
201 type: str
202 trusted_keys:
203 description: NTP trusted-key number.
204 type: list
205 elements: dict
206 suboptions:
207 key_id:
208 description: Trusted-Key number.
209 type: int
210 state:
211 description:
212 - The state the configuration should be left in.
213 - The states I(replaced) and I(overridden) have identical
214 behaviour for this module.
215 - Please refer to examples for more details.
216 type: str
217 choices:
218 - merged
219 - replaced
220 - overridden
221 - deleted
222 - parsed
223 - gathered
224 - rendered
225 default: merged
226 """
227
228 EXAMPLES = """
229 # Using merged
230
231 # Before state:
232 # -------------
233 # nxos-9k-rdo# show running-config ntp
234 # nxos-9k-rdo#
235
236 - name: Merge the provided configuration with the existing running configuration
237 cisco.nxos.nxos_ntp_global: &id001
238 config:
239 access_group:
240 peer:
241 - access_list: PeerAcl1
242 serve:
243 - access_list: ServeAcl1
244 authenticate: true
245 authentication_keys:
246 - id: 1001
247 key: vagwwtKfkv
248 encryption: 7
249 - id: 1002
250 key: vagwwtKfkvgthz
251 encryption: 7
252 logging: true
253 master:
254 stratum: 2
255 peers:
256 - peer: 192.0.2.1
257 key_id: 1
258 maxpoll: 15
259 minpoll: 5
260 vrf: default
261 - peer: 192.0.2.2
262 key_id: 2
263 prefer: true
264 vrf: siteA
265 servers:
266 - server: 198.51.100.1
267 key_id: 2
268 vrf: default
269 - server: 203.0.113.1
270 key_id: 1
271 vrf: siteB
272
273 # Task output
274 # -------------
275 # before: {}
276 #
277 # commands:
278 # - "ntp authenticate"
279 # - "ntp logging"
280 # - "ntp master 2"
281 # - "ntp authentication-keys 1001 md5 vagwwtKfkv 7"
282 # - "ntp authentication-keys 1002 md5 vagwwtKfkvgthz 7"
283 # - "ntp peer 192.0.2.1 use-vrf default key 1 minpoll 5 maxpoll 15"
284 # - "ntp peer 192.0.2.2 prefer use-vrf siteA key 2"
285 # - "ntp server 198.51.100.1 use-vrf default key 2"
286 # - "ntp server 203.0.113.1 use-vrf siteB key 1"
287 # - "ntp access-group peer PeerAcl1"
288 # - "ntp access-group serve ServeAcl1"
289 #
290 # after:
291 # access_group:
292 # peer:
293 # - access_list: PeerAcl1
294 # serve:
295 # - access_list: ServeAcl1
296 # authenticate: true
297 # authentication_keys:
298 # - id: 1001
299 # key: vagwwtKfkv
300 # encryption: 7
301 # - id: 1002
302 # key: vagwwtKfkvgthz
303 # encryption: 7
304 # logging: true
305 # master:
306 # stratum: 2
307 # peers:
308 # - peer: 192.0.2.1
309 # key_id: 1
310 # maxpoll: 15
311 # minpoll: 5
312 # vrf: default
313 # - peer: 192.0.2.2
314 # key_id: 2
315 # prefer: true
316 # vrf: siteA
317 # servers:
318 # - server: 198.51.100.1
319 # key_id: 2
320 # vrf: default
321 # - server: 203.0.113.1
322 # key_id: 1
323 # vrf: siteB
324
325 # After state:
326 # ------------
327 # nxos-9k-rdo# show running-config ntp
328 # ntp authenticate
329 # ntp logging
330 # ntp master 2
331 # ntp authentication-keys 1001 md5 vagwwtKfkv 7
332 # ntp authentication-keys 1002 md5 vagwwtKfkvgthz 7
333 # ntp peer 192.0.2.1 use-vrf default key 1 minpoll 5 maxpoll 15
334 # ntp peer 192.0.2.2 prefer use-vrf siteA key 2
335 # ntp server 198.51.100.1 use-vrf default key 2
336 # ntp server 203.0.113.1 use-vrf siteB key 1
337 # ntp access-group peer PeerAcl1
338 # ntp access-group serve ServeAcl1
339
340 # Using replaced
341
342 # Before state:
343 # ------------
344 # nxos-9k-rdo# show running-config ntp
345 # ntp authenticate
346 # ntp logging
347 # ntp master 2
348 # ntp authentication-keys 1001 md5 vagwwtKfkv 7
349 # ntp authentication-keys 1002 md5 vagwwtKfkvgthz 7
350 # ntp peer 192.0.2.1 use-vrf default key 1 minpoll 5 maxpoll 15
351 # ntp peer 192.0.2.2 prefer use-vrf siteA key 2
352 # ntp server 198.51.100.1 use-vrf default key 2
353 # ntp server 203.0.113.1 use-vrf siteB key 1
354 # ntp access-group peer PeerAcl1
355 # ntp access-group serve ServeAcl1
356
357 - name: Replace logging global configurations of listed logging global with provided configurations
358 cisco.nxos.nxos_ntp_global:
359 config:
360 access_group:
361 peer:
362 - access_list: PeerAcl2
363 serve:
364 - access_list: ServeAcl2
365 logging: true
366 master:
367 stratum: 2
368 peers:
369 - peer: 192.0.2.1
370 key_id: 1
371 maxpoll: 15
372 minpoll: 5
373 vrf: default
374 - peer: 192.0.2.5
375 key_id: 2
376 prefer: true
377 vrf: siteA
378 servers:
379 - server: 198.51.100.1
380 key_id: 2
381 vrf: default
382 state: replaced
383
384 # Task output
385 # -------------
386 # before:
387 # access_group:
388 # peer:
389 # - access_list: PeerAcl1
390 # serve:
391 # - access_list: ServeAcl1
392 # authenticate: true
393 # authentication_keys:
394 # - id: 1001
395 # key: vagwwtKfkv
396 # encryption: 7
397 # - id: 1002
398 # key: vagwwtKfkvgthz
399 # encryption: 7
400 # logging: true
401 # master:
402 # stratum: 2
403 # peers:
404 # - peer: 192.0.2.1
405 # key_id: 1
406 # maxpoll: 15
407 # minpoll: 5
408 # vrf: default
409 # - peer: 192.0.2.2
410 # key_id: 2
411 # prefer: true
412 # vrf: siteA
413 # servers:
414 # - server: 198.51.100.1
415 # key_id: 2
416 # vrf: default
417 # - server: 203.0.113.1
418 # key_id: 1
419 # vrf: siteB
420 #
421 # commands:
422 # - "no ntp authenticate"
423 # - "no ntp authentication-keys 1001 md5 vagwwtKfkv 7"
424 # - "no ntp authentication-keys 1002 md5 vagwwtKfkvgthz 7"
425 # - "ntp peer 192.0.2.5 prefer use-vrf siteA key 2"
426 # - "no ntp peer 192.0.2.2 prefer use-vrf siteA key 2"
427 # - "no ntp server 203.0.113.1 use-vrf siteB key 1"
428 # - "ntp access-group peer PeerAcl2"
429 # - "no ntp access-group peer PeerAcl1"
430 # - "ntp access-group serve ServeAcl2"
431 # - "no ntp access-group serve ServeAcl1"
432 #
433 # after:
434 # access_group:
435 # peer:
436 # - access_list: PeerAcl2
437 # serve:
438 # - access_list: ServeAcl2
439 # logging: true
440 # master:
441 # stratum: 2
442 # peers:
443 # - peer: 192.0.2.1
444 # key_id: 1
445 # maxpoll: 15
446 # minpoll: 5
447 # vrf: default
448 # - peer: 192.0.2.5
449 # key_id: 2
450 # prefer: true
451 # vrf: siteA
452 # servers:
453 # - server: 198.51.100.1
454 # key_id: 2
455 # vrf: default
456
457 # After state:
458 # ------------
459 # nxos-9k-rdo# show running-config ntp
460 # ntp logging
461 # ntp master 2
462 # ntp peer 192.0.2.1 use-vrf default key 1 minpoll 5 maxpoll 15
463 # ntp peer 192.0.2.5 prefer use-vrf siteA key 2
464 # ntp server 198.51.100.1 use-vrf default key 2
465 # ntp access-group peer PeerAcl2
466 # ntp access-group serve ServeAcl2
467
468 # Using deleted to delete all logging configurations
469
470 # Before state:
471 # ------------
472 # nxos-9k-rdo# show running-config ntp
473
474 - name: Delete all logging configuration
475 cisco.nxos.nxos_ntp_global:
476 state: deleted
477
478 # Task output
479 # -------------
480 # before:
481 # access_group:
482 # peer:
483 # - access_list: PeerAcl1
484 # serve:
485 # - access_list: ServeAcl1
486 # authenticate: true
487 # authentication_keys:
488 # - id: 1001
489 # key: vagwwtKfkv
490 # encryption: 7
491 # - id: 1002
492 # key: vagwwtKfkvgthz
493 # encryption: 7
494 # logging: true
495 # master:
496 # stratum: 2
497 # peers:
498 # - peer: 192.0.2.1
499 # key_id: 1
500 # maxpoll: 15
501 # minpoll: 5
502 # vrf: default
503 # - peer: 192.0.2.2
504 # key_id: 2
505 # prefer: true
506 # vrf: siteA
507 # servers:
508 # - server: 198.51.100.1
509 # key_id: 2
510 # vrf: default
511 # - server: 203.0.113.1
512 # key_id: 1
513 # vrf: siteB
514 #
515 # commands:
516 # - "no ntp authenticate"
517 # - "no ntp logging"
518 # - "no ntp master 2"
519 # - "no ntp authentication-keys 1001 md5 vagwwtKfkv 7"
520 # - "no ntp authentication-keys 1002 md5 vagwwtKfkvgthz 7"
521 # - "no ntp peer 192.0.2.1 use-vrf default key 1 minpoll 5 maxpoll 15"
522 # - "no ntp peer 192.0.2.2 prefer use-vrf siteA key 2"
523 # - "no ntp server 198.51.100.1 use-vrf default key 2"
524 # - "no ntp server 203.0.113.1 use-vrf siteB key 1"
525 # - "no ntp access-group peer PeerAcl1"
526 # - "no ntp access-group serve ServeAcl1"
527 #
528 # after: {}
529
530 # After state:
531 # ------------
532 # nxos-9k-rdo# show running-config ntp
533 # nxos-9k-rdo#
534
535 # Using rendered
536
537 - name: Render platform specific configuration lines with state rendered (without connecting to the device)
538 cisco.nxos.nxos_ntp_global:
539 config:
540 access_group:
541 peer:
542 - access_list: PeerAcl1
543 serve:
544 - access_list: ServeAcl1
545 authenticate: true
546 authentication_keys:
547 - id: 1001
548 key: vagwwtKfkv
549 encryption: 7
550 - id: 1002
551 key: vagwwtKfkvgthz
552 encryption: 7
553 logging: true
554 master:
555 stratum: 2
556 peers:
557 - peer: 192.0.2.1
558 key_id: 1
559 maxpoll: 15
560 minpoll: 5
561 vrf: default
562 - peer: 192.0.2.2
563 key_id: 2
564 prefer: true
565 vrf: siteA
566 servers:
567 - server: 198.51.100.1
568 key_id: 2
569 vrf: default
570 - server: 203.0.113.1
571 key_id: 1
572 vrf: siteB
573 state: rendered
574
575 # Task Output (redacted)
576 # -----------------------
577 # rendered:
578 # - "ntp authenticate"
579 # - "ntp logging"
580 # - "ntp master 2"
581 # - "ntp authentication-keys 1001 md5 vagwwtKfkv 7"
582 # - "ntp authentication-keys 1002 md5 vagwwtKfkvgthz 7"
583 # - "ntp peer 192.0.2.1 use-vrf default key 1 minpoll 5 maxpoll 15"
584 # - "ntp peer 192.0.2.2 prefer use-vrf siteA key 2"
585 # - "ntp server 198.51.100.1 use-vrf default key 2"
586 # - "ntp server 203.0.113.1 use-vrf siteB key 1"
587 # - "ntp access-group peer PeerAcl1"
588 # - "ntp access-group serve ServeAcl1"
589
590 # Using parsed
591
592 # parsed.cfg
593 # ------------
594 # ntp authenticate
595 # ntp logging
596 # ntp master 2
597 # ntp authentication-keys 1001 md5 vagwwtKfkv 7
598 # ntp authentication-keys 1002 md5 vagwwtKfkvgthz 7
599 # ntp peer 192.0.2.1 use-vrf default key 1 minpoll 5 maxpoll 15
600 # ntp peer 192.0.2.2 prefer use-vrf siteA key 2
601 # ntp server 198.51.100.1 use-vrf default key 2
602 # ntp server 203.0.113.1 use-vrf siteB key 1
603 # ntp access-group peer PeerAcl1
604 # ntp access-group serve ServeAcl1
605
606 - name: Parse externally provided ntp configuration
607 cisco.nxos.nxos_ntp_global:
608 running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}"
609 state: parsed
610
611 # Task output (redacted)
612 # -----------------------
613 # parsed:
614 # access_group:
615 # peer:
616 # - access_list: PeerAcl1
617 # serve:
618 # - access_list: ServeAcl1
619 # authenticate: true
620 # authentication_keys:
621 # - id: 1001
622 # key: vagwwtKfkv
623 # encryption: 7
624 # - id: 1002
625 # key: vagwwtKfkvgthz
626 # encryption: 7
627 # logging: true
628 # master:
629 # stratum: 2
630 # peers:
631 # - peer: 192.0.2.1
632 # key_id: 1
633 # maxpoll: 15
634 # minpoll: 5
635 # vrf: default
636 # - peer: 192.0.2.2
637 # key_id: 2
638 # prefer: true
639 # vrf: siteA
640 # servers:
641 # - server: 198.51.100.1
642 # key_id: 2
643 # vrf: default
644 # - server: 203.0.113.1
645 # key_id: 1
646 # vrf: siteB
647 """
648
649 RETURN = """
650 before:
651 description: The configuration prior to the module execution.
652 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
653 type: dict
654 sample: >
655 This output will always be in the same format as the
656 module argspec.
657 after:
658 description: The resulting configuration after module execution.
659 returned: when changed
660 type: dict
661 sample: >
662 This output will always be in the same format as the
663 module argspec.
664 commands:
665 description: The set of commands pushed to the remote device.
666 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
667 type: list
668 sample:
669 - ntp master stratum 2
670 - ntp peer 198.51.100.1 use-vrf test maxpoll 7
671 - ntp authentication-key 10 md5 wawyhanx2 7
672 - ntp access-group peer PeerAcl1
673 - ntp access-group peer PeerAcl2
674 - ntp access-group query-only QueryAcl1
675 rendered:
676 description: The provided configuration in the task rendered in device-native format (offline).
677 returned: when I(state) is C(rendered)
678 type: list
679 sample:
680 - ntp master stratum 2
681 - ntp peer 198.51.100.1 use-vrf test maxpoll 7
682 - ntp authentication-key 10 md5 wawyhanx2 7
683 - ntp access-group peer PeerAcl1
684 - ntp access-group peer PeerAcl2
685 - ntp access-group query-only QueryAcl1
686 gathered:
687 description: Facts about the network resource gathered from the remote device as structured data.
688 returned: when I(state) is C(gathered)
689 type: list
690 sample: >
691 This output will always be in the same format as the
692 module argspec.
693 parsed:
694 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
695 returned: when I(state) is C(parsed)
696 type: list
697 sample: >
698 This output will always be in the same format as the
699 module argspec.
700 """
701
702 from ansible.module_utils.basic import AnsibleModule
703
704 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ntp_global.ntp_global import (
705 Ntp_globalArgs,
706 )
707 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.ntp_global.ntp_global import (
708 Ntp_global,
709 )
710
711
712 def main():
713 """
714 Main entry point for module execution
715
716 :returns: the result form module invocation
717 """
718 module = AnsibleModule(
719 argument_spec=Ntp_globalArgs.argument_spec,
720 mutually_exclusive=[["config", "running_config"]],
721 required_if=[
722 ["state", "merged", ["config"]],
723 ["state", "replaced", ["config"]],
724 ["state", "overridden", ["config"]],
725 ["state", "rendered", ["config"]],
726 ["state", "parsed", ["running_config"]],
727 ],
728 supports_check_mode=True,
729 )
730
731 result = Ntp_global(module).execute_module()
732 module.exit_json(**result)
733
734
735 if __name__ == "__main__":
736 main()