Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_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 ios_ntp_global
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: ios_ntp_global
18 short_description: Resource module to configure NTP.
19 description:
20 - This module provides declarative management of ntp on Cisco IOS devices.
21 version_added: 2.5.0
22 author:
23 - Sagar Paul (@KB-perByte)
24 notes:
25 - Tested against Cisco IOSXE Version 17.3 on CML.
26 - This module works with connection C(network_cli).
27 options:
28 config:
29 description: A dictionary of ntp options
30 type: dict
31 suboptions:
32 access_group:
33 description: Control NTP access
34 type: dict
35 suboptions:
36 peer:
37 description: Provide full access
38 type: list
39 elements: dict
40 suboptions:
41 access_list: &access_group_acl
42 description: name or number of access list
43 type: str
44 kod: &kod
45 description: Send a Kiss-o-Death packet for failing peers
46 type: bool
47 ipv4: &ipv4
48 description: ipv4 access lists (Default not idempotent)
49 type: bool
50 ipv6: &ipv6
51 description: ipv6 access lists (Default not idempotent)
52 type: bool
53 query_only:
54 description: Allow only control queries
55 type: list
56 elements: dict
57 suboptions:
58 access_list: *access_group_acl
59 kod: *kod
60 ipv4: *ipv4
61 ipv6: *ipv6
62 serve:
63 description: Provide server and query access
64 type: list
65 elements: dict
66 suboptions:
67 access_list: *access_group_acl
68 kod: *kod
69 ipv4: *ipv4
70 ipv6: *ipv6
71 serve_only:
72 description: Provide only server access
73 type: list
74 elements: dict
75 suboptions:
76 access_list: *access_group_acl
77 kod: *kod
78 ipv4: *ipv4
79 ipv6: *ipv6
80 allow:
81 description: Allow processing of packets
82 type: dict
83 suboptions:
84 control:
85 description: Allow processing control mode packets
86 type: dict
87 suboptions:
88 rate_limit:
89 description: Rate-limit delay.
90 type: int
91 private:
92 description: Allow processing private mode packets
93 type: bool
94 authenticate:
95 description: Authenticate time sources
96 type: bool
97 authentication_keys:
98 description: Authentication key for trusted time sources
99 type: list
100 elements: dict
101 suboptions:
102 id:
103 description: Key number
104 type: int
105 algorithm:
106 description: Authentication type
107 type: str
108 key:
109 description: Password
110 type: str
111 encryption:
112 description: Authentication key encryption type
113 type: int
114 broadcast_delay:
115 description: Estimated round-trip delay
116 type: int
117 clock_period:
118 description: Length of hardware clock tick, clock period in 2^-32 seconds
119 type: int
120 logging:
121 description: Enable NTP message logging
122 type: bool
123 master:
124 description: Act as NTP master clock
125 type: dict
126 suboptions:
127 enabled:
128 description: Enable master clock
129 type: bool
130 stratum:
131 description: Stratum number
132 type: int
133 max_associations:
134 description: Set maximum number of associations
135 type: int
136 max_distance:
137 description: Maximum Distance for synchronization
138 type: int
139 min_distance:
140 description: Minimum distance to consider for clockhop
141 type: int
142 orphan:
143 description: Threshold Stratum for orphan mode
144 type: int
145 panic_update:
146 description: Reject time updates > panic threshold (default 1000Sec)
147 type: bool
148 passive:
149 description: NTP passive mode
150 type: bool
151 peers:
152 description: Configure NTP peer
153 type: list
154 elements: dict
155 suboptions:
156 peer:
157 description: ipv4/ipv6 address or hostname of the peer
158 type: str
159 use_ipv4: &use_ipv4
160 description: Use IP for DNS resolution
161 type: bool
162 use_ipv6: &use_ipv6
163 description: Use IPv6 for DNS resolution
164 type: bool
165 vrf: &vrf
166 description: VPN Routing/Forwarding Information
167 type: str
168 burst: &burst
169 description: Send a burst when peer is reachable (Default)
170 type: bool
171 iburst: &iburst
172 description: Send a burst when peer is unreachable (Default)
173 type: bool
174 key_id: &key
175 description: Configure peer authentication key
176 type: int
177 aliases:
178 - key
179 maxpoll: &maxpoll
180 description: Maximum poll interval Poll value in Log2
181 type: int
182 minpoll: &minpoll
183 description: Minimum poll interval Poll value in Log2
184 type: int
185 normal_sync: &normal_sync
186 description: Disable rapid sync at startup
187 type: bool
188 prefer: &prefer
189 description: Prefer this peer when possible
190 type: bool
191 source: &source
192 description: Interface for source address
193 type: str
194 version: &version
195 description: Configure NTP version
196 type: int
197 servers:
198 description: Configure NTP server
199 type: list
200 elements: dict
201 suboptions:
202 server:
203 description: ipv4/ipv6 address or hostname of the server
204 type: str
205 use_ipv4: *use_ipv4
206 use_ipv6: *use_ipv6
207 vrf: *vrf
208 burst: *burst
209 iburst: *iburst
210 key_id: *key
211 maxpoll: *maxpoll
212 minpoll: *minpoll
213 normal_sync: *normal_sync
214 prefer: *prefer
215 source: *source
216 version: *version
217 source:
218 description: Configure interface for source address
219 type: str
220 trusted_keys:
221 description: Key numbers for trusted time sources
222 type: list
223 elements: dict
224 suboptions:
225 range_start:
226 description: Start / key number
227 type: int
228 range_end:
229 description: End key number
230 type: int
231 update_calendar:
232 description: Periodically update calendar with NTP time
233 type: bool
234 running_config:
235 description:
236 - This option is used only with state I(parsed).
237 - The value of this option should be the output received from the IOS device
238 by executing the command B(show running-config | section ^ntp).
239 - The state I(parsed) reads the configuration from C(running_config) option and
240 transforms it into Ansible structured data as per the resource module's argspec
241 and the value is then returned in the I(parsed) key within the result.
242 type: str
243 state:
244 choices:
245 - merged
246 - replaced
247 - overridden
248 - deleted
249 - rendered
250 - gathered
251 - parsed
252 default: merged
253 description:
254 - The state the configuration should be left in
255 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
256 on the device.
257 - The state I(rendered) will transform the configuration in C(config) option to
258 platform specific CLI commands which will be returned in the I(rendered) key
259 within the result. For state I(rendered) active connection to remote host is
260 not required.
261 - The states I(replaced) and I(overridden) have identical
262 behaviour for this module.
263 - The state I(gathered) will fetch the running configuration from device and transform
264 it into structured data in the format as per the resource module argspec and
265 the value is returned in the I(gathered) key within the result.
266 - The state I(parsed) reads the configuration from C(running_config) option and
267 transforms it into JSON format as per the resource module parameters and the
268 value is returned in the I(parsed) key within the result. The value of C(running_config)
269 option should be the same format as the output of command
270 I(show running-config | section ^ntp) executed on device. For state I(parsed) active
271 connection to remote host is not required.
272 type: str
273 """
274
275 EXAMPLES = """
276 # Using state: merged
277
278 # Before state:
279 # -------------
280
281 # router-ios#show running-config | section ^ntp
282 # --------------------- EMPTY -----------------
283
284 # Merged play:
285 # ------------
286
287 - name: Apply the provided configuration
288 cisco.ios.ios_ntp_global:
289 config:
290 access_group:
291 peer:
292 - access_list: DHCP-Server
293 ipv4: true
294 kod: true
295 - access_list: preauth_ipv6_acl
296 ipv6: true
297 kod: true
298 - access_list: "2"
299 kod: true
300 query_only:
301 - access_list: "10"
302 allow:
303 control:
304 rate_limit: 4
305 private: true
306 authenticate: true
307 authentication_keys:
308 - algorithm: md5
309 encryption: 22
310 id: 2
311 key: SomeSecurePassword
312 broadcast_delay: 22
313 clock_period: 5
314 logging: true
315 master:
316 stratum: 4
317 max_associations: 34
318 max_distance: 3
319 min_distance: 10
320 orphan: 4
321 panic_update: true
322 peers:
323 - peer: 172.16.1.10
324 version: 2
325 - key: 2
326 minpoll: 5
327 peer: 172.16.1.11
328 prefer: true
329 version: 2
330 - peer: checkPeerDomainIpv4.com
331 prefer: true
332 use_ipv4: true
333 - peer: checkPeerDomainIpv6.com
334 use_ipv6: true
335 - peer: testPeerDomainIpv6.com
336 prefer: true
337 use_ipv6: true
338 servers:
339 - server: 172.16.1.12
340 version: 2
341 - server: checkServerDomainIpv6.com
342 use_ipv6: true
343 - server: 172.16.1.13
344 source: GigabitEthernet0/1
345 source: GigabitEthernet0/1
346 trusted_keys:
347 - range_end: 3
348 range_start: 3
349 - range_start: 21
350 state: merged
351
352 # Commands Fired:
353 # ---------------
354
355 # "commands": [
356 # "ntp allow mode control 4",
357 # "ntp allow mode private",
358 # "ntp authenticate",
359 # "ntp broadcastdelay 22",
360 # "ntp clock-period 5",
361 # "ntp logging",
362 # "ntp master 4",
363 # "ntp max-associations 34",
364 # "ntp maxdistance 3",
365 # "ntp mindistance 10",
366 # "ntp orphan 4",
367 # "ntp panic update",
368 # "ntp source GigabitEthernet0/1",
369 # "ntp access-group ipv4 peer DHCP-Server kod",
370 # "ntp access-group ipv6 peer preauth_ipv6_acl kod",
371 # "ntp access-group peer 2 kod",
372 # "ntp access-group query-only 10",
373 # "ntp authentication-key 2 md5 SomeSecurePassword 22",
374 # "ntp peer 172.16.1.10 version 2",
375 # "ntp peer 172.16.1.11 key 2 minpoll 5 prefer version 2",
376 # "ntp peer ip checkPeerDomainIpv4.com prefer",
377 # "ntp peer ipv6 checkPeerDomainIpv6.com",
378 # "ntp peer ipv6 testPeerDomainIpv6.com prefer",
379 # "ntp server 172.16.1.12 version 2",
380 # "ntp server ipv6 checkServerDomainIpv6.com",
381 # "ntp server 172.16.1.13 source GigabitEthernet0/1",
382 # "ntp trusted-key 3 - 3",
383 # "ntp trusted-key 21"
384 # ],
385
386 # After state:
387 # ------------
388
389 # router-ios#show running-config | section ^ntp
390 # ntp max-associations 34
391 # ntp logging
392 # ntp allow mode control 4
393 # ntp panic update
394 # ntp authentication-key 2 md5 0635002C497D0C1A1005173B0D17393C2B3A37 7
395 # ntp authenticate
396 # ntp trusted-key 3 - 3
397 # ntp trusted-key 21
398 # ntp orphan 4
399 # ntp mindistance 10
400 # ntp maxdistance 3
401 # ntp broadcastdelay 22
402 # ntp source GigabitEthernet0/1
403 # ntp access-group peer 2 kod
404 # ntp access-group ipv6 peer preauth_ipv6_acl kod
405 # ntp master 4
406 # ntp peer 172.16.1.10 version 2
407 # ntp peer 172.16.1.11 key 2 minpoll 5 prefer version 2
408 # ntp server 172.16.1.12 version 2
409 # ntp server 172.16.1.13 source GigabitEthernet0/1
410 # ntp peer ip checkPeerDomainIpv4.com prefer
411 # ntp peer ipv6 checkPeerDomainIpv6.com
412 # ntp peer ipv6 testPeerDomainIpv6.com prefer
413 # ntp server ipv6 checkServerDomainIpv6.com
414
415 # Using state: deleted
416
417 # Before state:
418 # -------------
419
420 # router-ios#show running-config | section ^ntp
421 # ntp max-associations 34
422 # ntp logging
423 # ntp allow mode control 4
424 # ntp panic update
425 # ntp authentication-key 2 md5 0635002C497D0C1A1005173B0D17393C2B3A37 7
426 # ntp authenticate
427 # ntp trusted-key 3 - 3
428 # ntp trusted-key 21
429 # ntp orphan 4
430 # ntp mindistance 10
431 # ntp maxdistance 3
432 # ntp broadcastdelay 22
433 # ntp source GigabitEthernet0/1
434 # ntp access-group peer 2 kod
435 # ntp access-group ipv6 peer preauth_ipv6_acl kod
436 # ntp master 4
437 # ntp peer 172.16.1.10 version 2
438 # ntp peer 172.16.1.11 key 2 minpoll 5 prefer version 2
439 # ntp server 172.16.1.12 version 2
440 # ntp server 172.16.1.13 source GigabitEthernet0/1
441 # ntp peer ip checkPeerDomainIpv4.com prefer
442 # ntp peer ipv6 checkPeerDomainIpv6.com
443 # ntp peer ipv6 testPeerDomainIpv6.com prefer
444 # ntp server ipv6 checkServerDomainIpv6.com
445
446 # Deleted play:
447 # -------------
448
449 - name: Remove all existing configuration
450 cisco.ios.ios_ntp_global:
451 state: deleted
452
453 # Commands Fired:
454 # ---------------
455
456 # "commands": [
457 # "no ntp allow mode control 4",
458 # "no ntp authenticate",
459 # "no ntp broadcastdelay 22",
460 # "no ntp logging",
461 # "no ntp master 4",
462 # "no ntp max-associations 34",
463 # "no ntp maxdistance 3",
464 # "no ntp mindistance 10",
465 # "no ntp orphan 4",
466 # "no ntp panic update",
467 # "no ntp source GigabitEthernet0/1",
468 # "no ntp access-group peer 2 kod",
469 # "no ntp access-group ipv6 peer preauth_ipv6_acl kod",
470 # "no ntp authentication-key 2 md5 0635002C497D0C1A1005173B0D17393C2B3A37 7",
471 # "no ntp peer 172.16.1.10 version 2",
472 # "no ntp peer 172.16.1.11 key 2 minpoll 5 prefer version 2",
473 # "no ntp peer ip checkPeerDomainIpv4.com prefer",
474 # "no ntp peer ipv6 checkPeerDomainIpv6.com",
475 # "no ntp peer ipv6 testPeerDomainIpv6.com prefer",
476 # "no ntp server 172.16.1.12 version 2",
477 # "no ntp server 172.16.1.13 source GigabitEthernet0/1",
478 # "no ntp server ipv6 checkServerDomainIpv6.com",
479 # "no ntp trusted-key 21",
480 # "no ntp trusted-key 3 - 3"
481 # ],
482
483 # After state:
484 # ------------
485
486 # router-ios#show running-config | section ^ntp
487 # --------------------- EMPTY -----------------
488
489 # Using state: overridden
490
491 # Before state:
492 # -------------
493
494 # router-ios#show running-config | section ^ntp
495 # ntp panic update
496 # ntp authentication-key 2 md5 00371C0B01680E051A33497E080A16001D1908 7
497 # ntp authenticate
498 # ntp trusted-key 3 - 4
499 # ntp trusted-key 21
500 # ntp source GigabitEthernet0/1
501 # ntp peer 172.16.1.10 version 2
502 # ntp server 172.16.1.12 version 2
503 # ntp peer ip checkPeerDomainIpv4.com prefer
504 # ntp server ipv6 checkServerDomainIpv6.com
505
506 # Overridden play:
507 # ----------------
508
509 - name: Override commands with provided configuration
510 cisco.ios.ios_ntp_global:
511 config:
512 peers:
513 - peer: ipv6DomainNew.com
514 use_ipv6: true
515 - peer: 172.16.1.100
516 prefer: true
517 use_ipv4: true
518 access_group:
519 peer:
520 - access_list: DHCP-Server
521 ipv6: true
522 state: overridden
523
524 # Commands Fired:
525 # ---------------
526 # "commands": [
527 # "no ntp authenticate",
528 # "no ntp panic update",
529 # "no ntp source GigabitEthernet0/1",
530 # "ntp access-group ipv6 peer DHCP-Server",
531 # "no ntp authentication-key 2 md5 00371C0B01680E051A33497E080A16001D1908 7",
532 # "ntp peer ipv6 ipv6DomainNew.com",
533 # "ntp peer 172.16.1.100 prefer",
534 # "no ntp peer 172.16.1.10 version 2",
535 # "no ntp peer ip checkPeerDomainIpv4.com prefer",
536 # "no ntp server 172.16.1.12 version 2",
537 # "no ntp server ipv6 checkServerDomainIpv6.com",
538 # "no ntp trusted-key 21",
539 # "no ntp trusted-key 3 - 4"
540 # ],
541
542 # After state:
543 # ------------
544
545 # router-ios#show running-config | section ^ntp
546 # ntp access-group ipv6 peer DHCP-Server
547 # ntp peer ipv6 ipv6DomainNew.com
548 # ntp peer 172.16.1.100 prefer
549
550 # Using state: replaced
551
552 # Before state:
553 # -------------
554
555 # router-ios#show running-config | section ^ntp
556 # ntp access-group ipv6 peer DHCP-Server
557 # ntp peer ipv6 ipv6DomainNew.com
558 # ntp peer 172.16.1.100 prefer
559
560 # Replaced play:
561 # --------------
562
563 - name: Replace commands with provided configuration
564 cisco.ios.ios_ntp_global:
565 config:
566 broadcast_delay: 22
567 clock_period: 5
568 logging: true
569 master:
570 stratum: 4
571 max_associations: 34
572 max_distance: 3
573 min_distance: 10
574 orphan: 4
575 state: replaced
576
577 # Commands Fired:
578 # ---------------
579
580 # "commands": [
581 # "ntp broadcastdelay 22",
582 # "ntp clock-period 5",
583 # "ntp logging",
584 # "ntp master 4",
585 # "ntp max-associations 34",
586 # "ntp maxdistance 3",
587 # "ntp mindistance 10",
588 # "ntp orphan 4",
589 # "no ntp access-group ipv6 peer DHCP-Server",
590 # "no ntp peer 172.16.1.100 prefer",
591 # "no ntp peer ipv6 ipv6DomainNew.com"
592 # ],
593
594 # After state:
595 # ------------
596
597 # router-ios#show running-config | section ^ntp
598 # ntp max-associations 34
599 # ntp logging
600 # ntp orphan 4
601 # ntp mindistance 10
602 # ntp maxdistance 3
603 # ntp broadcastdelay 22
604 # ntp master 4
605
606 # Using state: gathered
607
608 # Before state:
609 # -------------
610
611 # router-ios#show running-config | section ^ntp
612 # ntp max-associations 34
613 # ntp logging
614 # ntp allow mode control 4
615 # ntp panic update
616 # ntp authentication-key 2 md5 0635002C497D0C1A1005173B0D17393C2B3A37 7
617 # ntp authenticate
618 # ntp trusted-key 3 - 3
619 # ntp trusted-key 21
620 # ntp orphan 4
621 # ntp mindistance 10
622 # ntp maxdistance 3
623 # ntp broadcastdelay 22
624 # ntp source GigabitEthernet0/1
625 # ntp access-group peer 2 kod
626 # ntp access-group ipv6 peer preauth_ipv6_acl kod
627 # ntp master 4
628 # ntp update-calendar
629 # ntp peer 172.16.1.10 version 2
630 # ntp peer 172.16.1.11 key 2 minpoll 5 prefer version 2
631 # ntp server 172.16.1.12 version 2
632 # ntp server 172.16.1.13 source GigabitEthernet0/1
633 # ntp peer ip checkPeerDomainIpv4.com prefer
634 # ntp peer ipv6 checkPeerDomainIpv6.com
635 # ntp peer ipv6 testPeerDomainIpv6.com prefer
636 # ntp server ipv6 checkServerDomainIpv6.com
637
638 # Gathered play:
639 # --------------
640
641 - name: Gather listed ntp config
642 cisco.ios.ios_ntp_global:
643 state: gathered
644
645 # Module Execution Result:
646 # ------------------------
647
648 # "gathered": {
649 # "access_group": {
650 # "peer": [
651 # {
652 # "access_list": "2",
653 # "kod": true
654 # },
655 # {
656 # "access_list": "preauth_ipv6_acl",
657 # "ipv6": true,
658 # "kod": true
659 # }
660 # ]
661 # },
662 # "allow": {
663 # "control": {
664 # "rate_limit": 4
665 # }
666 # },
667 # "authenticate": true,
668 # "authentication_keys": [
669 # {
670 # "algorithm": "md5",
671 # "encryption": 7,
672 # "id": 2,
673 # "key": "0635002C497D0C1A1005173B0D17393C2B3A37"
674 # }
675 # ],
676 # "broadcast_delay": 22,
677 # "logging": true,
678 # "master": {
679 # "stratum": 4
680 # },
681 # "max_associations": 34,
682 # "max_distance": 3,
683 # "min_distance": 10,
684 # "orphan": 4,
685 # "panic_update": true,
686 # "peers": [
687 # {
688 # "peer": "172.16.1.10",
689 # "version": 2
690 # },
691 # {
692 # "key": 2,
693 # "minpoll": 5,
694 # "peer": "172.16.1.11",
695 # "prefer": true,
696 # "version": 2
697 # },
698 # {
699 # "peer": "checkPeerDomainIpv4.com",
700 # "prefer": true,
701 # "use_ipv4": true
702 # },
703 # {
704 # "peer": "checkPeerDomainIpv6.com",
705 # "use_ipv6": true
706 # },
707 # {
708 # "peer": "testPeerDomainIpv6.com",
709 # "prefer": true,
710 # "use_ipv6": true
711 # }
712 # ],
713 # "servers": [
714 # {
715 # "server": "172.16.1.12",
716 # "version": 2
717 # },
718 # {
719 # "server": "172.16.1.13",
720 # "source": "GigabitEthernet0/1"
721 # },
722 # {
723 # "server": "checkServerDomainIpv6.com",
724 # "use_ipv6": true
725 # }
726 # ],
727 # "source": "GigabitEthernet0/1",
728 # "trusted_keys": [
729 # {
730 # "range_start": 21
731 # },
732 # {
733 # "range_end": 3,
734 # "range_start": 3
735 # }
736 # ],
737 # "update_calendar": true
738 # },
739
740 # After state:
741 # -------------
742
743 # router-ios#show running-config | section ^ntp
744 # ntp max-associations 34
745 # ntp logging
746 # ntp allow mode control 4
747 # ntp panic update
748 # ntp authentication-key 2 md5 0635002C497D0C1A1005173B0D17393C2B3A37 7
749 # ntp authenticate
750 # ntp trusted-key 3 - 3
751 # ntp trusted-key 21
752 # ntp orphan 4
753 # ntp mindistance 10
754 # ntp maxdistance 3
755 # ntp broadcastdelay 22
756 # ntp source GigabitEthernet0/1
757 # ntp access-group peer 2 kod
758 # ntp access-group ipv6 peer preauth_ipv6_acl kod
759 # ntp master 4
760 # ntp update-calendar
761 # ntp peer 172.16.1.10 version 2
762 # ntp peer 172.16.1.11 key 2 minpoll 5 prefer version 2
763 # ntp server 172.16.1.12 version 2
764 # ntp server 172.16.1.13 source GigabitEthernet0/1
765 # ntp peer ip checkPeerDomainIpv4.com prefer
766 # ntp peer ipv6 checkPeerDomainIpv6.com
767 # ntp peer ipv6 testPeerDomainIpv6.com prefer
768 # ntp server ipv6 checkServerDomainIpv6.com
769
770 # Using state: rendered
771
772 # Rendered play:
773 # --------------
774
775 - name: Render the commands for provided configuration
776 cisco.ios.ios_ntp_global:
777 config:
778 access_group:
779 peer:
780 - access_list: DHCP-Server
781 ipv4: true
782 kod: true
783 - access_list: preauth_ipv6_acl
784 ipv6: true
785 kod: true
786 - access_list: "2"
787 kod: true
788 query_only:
789 - access_list: "10"
790 allow:
791 control:
792 rate_limit: 4
793 private: true
794 authenticate: true
795 authentication_keys:
796 - algorithm: md5
797 encryption: 22
798 id: 2
799 key: SomeSecurePassword
800 broadcast_delay: 22
801 clock_period: 5
802 logging: true
803 master:
804 stratum: 4
805 max_associations: 34
806 max_distance: 3
807 min_distance: 10
808 orphan: 4
809 panic_update: true
810 peers:
811 - peer: 172.16.1.10
812 version: 2
813 - key: 2
814 minpoll: 5
815 peer: 172.16.1.11
816 prefer: true
817 version: 2
818 - peer: checkPeerDomainIpv4.com
819 prefer: true
820 use_ipv4: true
821 - peer: checkPeerDomainIpv6.com
822 use_ipv6: true
823 - peer: testPeerDomainIpv6.com
824 prefer: true
825 use_ipv6: true
826 servers:
827 - server: 172.16.1.12
828 version: 2
829 - server: checkServerDomainIpv6.com
830 use_ipv6: true
831 - server: 172.16.1.13
832 source: GigabitEthernet0/1
833 source: GigabitEthernet0/1
834 trusted_keys:
835 - range_end: 3
836 range_start: 10
837 - range_start: 21
838 update_calendar: true
839 state: rendered
840
841 # Module Execution Result:
842 # ------------------------
843
844 # "rendered": [
845 # "ntp allow mode control 4",
846 # "ntp allow mode private",
847 # "ntp authenticate",
848 # "ntp broadcastdelay 22",
849 # "ntp clock-period 5",
850 # "ntp logging",
851 # "ntp master 4",
852 # "ntp max-associations 34",
853 # "ntp maxdistance 3",
854 # "ntp mindistance 10",
855 # "ntp orphan 4",
856 # "ntp panic update",
857 # "ntp source GigabitEthernet0/1",
858 # "ntp update-calendar",
859 # "ntp access-group ipv4 peer DHCP-Server kod",
860 # "ntp access-group ipv6 peer preauth_ipv6_acl kod",
861 # "ntp access-group peer 2 kod",
862 # "ntp access-group query-only 10",
863 # "ntp authentication-key 2 md5 SomeSecurePassword 22",
864 # "ntp peer 172.16.1.10 version 2",
865 # "ntp peer 172.16.1.11 key 2 minpoll 5 prefer version 2",
866 # "ntp peer ip checkPeerDomainIpv4.com prefer",
867 # "ntp peer ipv6 checkPeerDomainIpv6.com",
868 # "ntp peer ipv6 testPeerDomainIpv6.com prefer",
869 # "ntp server 172.16.1.12 version 2",
870 # "ntp server ipv6 checkServerDomainIpv6.com",
871 # "ntp server 172.16.1.13 source GigabitEthernet0/1",
872 # "ntp trusted-key 3 - 3",
873 # "ntp trusted-key 21"
874 # ]
875
876 # Using state: parsed
877
878 # File: parsed.cfg
879 # ----------------
880
881 # ntp allow mode control 4
882 # ntp allow mode private
883 # ntp authenticate
884 # ntp broadcastdelay 22
885 # ntp clock-period 5
886 # ntp logging
887 # ntp master 4
888 # ntp max-associations 34
889 # ntp maxdistance 3
890 # ntp mindistance 10
891 # ntp orphan 4
892 # ntp panic update
893 # ntp source GigabitEthernet0/1
894 # ntp update-calendar
895 # ntp access-group ipv4 peer DHCP-Server kod
896 # ntp access-group ipv6 peer preauth_ipv6_acl kod
897 # ntp access-group peer 2 kod
898 # ntp access-group query-only 10
899 # ntp authentication-key 2 md5 SomeSecurePassword 22
900 # ntp peer 172.16.1.10 version 2
901 # ntp peer 172.16.1.11 key 2 minpoll 5 prefer version 2
902 # ntp peer ip checkPeerDomainIpv4.com prefer
903 # ntp peer ipv6 checkPeerDomainIpv6.com
904 # ntp peer ipv6 testPeerDomainIpv6.com prefer
905 # ntp server 172.16.1.12 version 2
906 # ntp server ipv6 checkServerDomainIpv6.com
907 # ntp server 172.16.1.13 source GigabitEthernet0/1
908 # ntp trusted-key 3 - 13
909 # ntp trusted-key 21
910
911 # Parsed play:
912 # ------------
913
914 - name: Parse the provided configuration with the existing running configuration
915 cisco.ios.ios_ntp_global:
916 running_config: "{{ lookup('file', 'parsed.cfg') }}"
917 state: parsed
918
919 # Module Execution Result:
920 # ------------------------
921
922 # "parsed": {
923 # "access_group": {
924 # "peer": [
925 # {
926 # "access_list": "2",
927 # "kod": true
928 # },
929 # {
930 # "access_list": "DHCP-Server",
931 # "ipv4": true,
932 # "kod": true
933 # },
934 # {
935 # "access_list": "preauth_ipv6_acl",
936 # "ipv6": true,
937 # "kod": true
938 # }
939 # ],
940 # "query_only": [
941 # {
942 # "access_list": "10"
943 # }
944 # ]
945 # },
946 # "allow": {
947 # "control": {
948 # "rate_limit": 4
949 # },
950 # "private": true
951 # },
952 # "authenticate": true,
953 # "authentication_keys": [
954 # {
955 # "algorithm": "md5",
956 # "encryption": 22,
957 # "id": 2,
958 # "key": "SomeSecurePassword"
959 # }
960 # ],
961 # "broadcast_delay": 22,
962 # "clock_period": 5,
963 # "logging": true,
964 # "master": {
965 # "stratum": 4
966 # },
967 # "max_associations": 34,
968 # "max_distance": 3,
969 # "min_distance": 10,
970 # "orphan": 4,
971 # "panic_update": true,
972 # "peers": [
973 # {
974 # "peer": "172.16.1.10",
975 # "version": 2
976 # },
977 # {
978 # "peer": "checkPeerDomainIpv6.com",
979 # "use_ipv6": true
980 # }
981 # ],
982 # "servers": [
983 # {
984 # "server": "172.16.1.12",
985 # "version": 2
986 # },
987 # {
988 # "server": "172.16.1.13",
989 # "source": "GigabitEthernet0/1"
990 # },
991 # {
992 # "server": "checkServerDomainIpv6.com",
993 # "use_ipv6": true
994 # }
995 # ],
996 # "source": "GigabitEthernet0/1",
997 # "trusted_keys": [
998 # {
999 # "range_start": 21
1000 # },
1001 # {
1002 # "range_end": 13,
1003 # "range_start": 3
1004 # }
1005 # ],
1006 # "update_calendar": true
1007 # }
1008 """
1009
1010 RETURN = """
1011 before:
1012 description: The configuration prior to the module execution.
1013 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
1014 type: dict
1015 sample: >
1016 This output will always be in the same format as the
1017 module argspec.
1018 after:
1019 description: The resulting configuration after module execution.
1020 returned: when changed
1021 type: dict
1022 sample: >
1023 This output will always be in the same format as the
1024 module argspec.
1025 commands:
1026 description: The set of commands pushed to the remote device.
1027 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
1028 type: list
1029 sample:
1030 - ntp peer 20.18.11.3 key 6 minpoll 15 prefer version 2
1031 - ntp access-group ipv4 peer DHCP-Server kod
1032 - ntp trusted-key 9 - 96
1033 - ntp master stratum 2
1034 - ntp orphan 4
1035 - ntp panic update
1036 rendered:
1037 description: The provided configuration in the task rendered in device-native format (offline).
1038 returned: when state is I(rendered)
1039 type: list
1040 sample:
1041 - ntp master stratum 2
1042 - ntp server ip testserver.com prefer
1043 - ntp authentication-key 2 md5 testpass 22
1044 - ntp allow mode control 4
1045 - ntp max-associations 34
1046 - ntp broadcastdelay 22
1047 gathered:
1048 description: Facts about the network resource gathered from the remote device as structured data.
1049 returned: when I(state) is C(gathered)
1050 type: list
1051 sample: >
1052 This output will always be in the same format as the
1053 module argspec.
1054 parsed:
1055 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
1056 returned: when I(state) is C(parsed)
1057 type: list
1058 sample: >
1059 This output will always be in the same format as the
1060 module argspec.
1061 """
1062
1063 from ansible.module_utils.basic import AnsibleModule
1064
1065 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.ntp_global.ntp_global import (
1066 Ntp_globalArgs,
1067 )
1068 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.ntp_global.ntp_global import (
1069 Ntp_global,
1070 )
1071
1072
1073 def main():
1074 """
1075 Main entry point for module execution
1076
1077 :returns: the result form module invocation
1078 """
1079 module = AnsibleModule(
1080 argument_spec=Ntp_globalArgs.argument_spec,
1081 mutually_exclusive=[["config", "running_config"]],
1082 required_if=[
1083 ["state", "merged", ["config"]],
1084 ["state", "replaced", ["config"]],
1085 ["state", "overridden", ["config"]],
1086 ["state", "rendered", ["config"]],
1087 ["state", "parsed", ["running_config"]],
1088 ],
1089 supports_check_mode=True,
1090 )
1091
1092 result = Ntp_global(module).execute_module()
1093 module.exit_json(**result)
1094
1095
1096 if __name__ == "__main__":
1097 main()