Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_service.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2023 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_service
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 ---
18 module: ios_service
19 short_description: Resource module to configure service.
20 description:
21 - This module configures and manages service attributes on IOS platforms
22 version_added: 4.6.0
23 author:
24 - Ambroise Rosset (@earendilfr)
25 - Sagar Paul (@KB-perByte)
26 notes:
27 - Tested against Cisco IOSXE Version 17.9.1a on CML.
28 - This module works with connection C(network_cli).
29 See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html)
30 options:
31 config:
32 description: A dictionary of service configuration
33 suboptions:
34 call_home:
35 description: Cisco call-home service
36 type: bool
37 compress_config:
38 description: Compress the nvram configuration file
39 type: bool
40 config:
41 description: TFTP load config files
42 type: bool
43 counters:
44 description:
45 - Control aging of interface counters by setting the maximum counter aging threshold
46 type: int
47 default: 0
48 dhcp:
49 description: Enable DHCP server and relay agent
50 type: bool
51 default: true
52 disable_ip_fast_frag:
53 description: Disable IP particle-based fast fragmentation
54 type: bool
55 exec_callback:
56 description: Enable exec callback
57 type: bool
58 exec_wait:
59 description: Delay EXEC startup on noisy lines
60 type: bool
61 hide_telnet_addresses:
62 description: Hide destination addresses in telnet command
63 type: bool
64 internal:
65 description: Enable/Disable Internal commands
66 type: bool
67 linenumber:
68 description: enable line number banner for each exec
69 type: bool
70 log:
71 description: log backtrace
72 type: bool
73 log_hidden:
74 description: Enable syslog msgs for hidden/internal commands
75 type: bool
76 nagle:
77 description: Enable Nagle's congestion control algorithm
78 type: bool
79 old_slip_prompts:
80 description: Allow old scripts to operate with slip/ppp
81 type: bool
82 pad:
83 description: Enable PAD commands
84 type: bool
85 pad_cmns:
86 description: Enable PAD over CMNS connections
87 type: bool
88 pad_from_xot:
89 description: Accept XOT to PAD connections
90 type: bool
91 pad_to_xot:
92 description: Allow outgoing PAD over XOT connections
93 type: bool
94 password_encryption:
95 description: Encrypt system passwords
96 type: bool
97 password_recovery:
98 description: Password recovery
99 type: bool
100 default: true
101 prompt:
102 description: Enable mode specific prompt
103 type: bool
104 default: true
105 private_config_encryption:
106 description: Enable private config file encryption
107 type: bool
108 pt_vty_logging:
109 description: Log significant VTY-Async events
110 type: bool
111 scripting:
112 description: scripting
113 type: bool
114 sequence_numbers:
115 description: Stamp logger messages with a sequence number
116 type: bool
117 slave_coredump:
118 description: slave-coredump
119 type: bool
120 slave_log:
121 description: Enable log capability of slave IPs
122 type: bool
123 default: true
124 tcp_keepalives_in:
125 description: Generate keepalives on idle incoming network connections
126 type: bool
127 tcp_keepalives_out:
128 description: Generate keepalives on idle outgoing network connections
129 type: bool
130 tcp_small_servers:
131 description:
132 - TCP small servers are servers (daemons, in Unix parlance) that run in the
133 router which are useful for diagnostics.
134 suboptions:
135 enable:
136 description: Enable small TCP servers (e.g., ECHO)
137 type: bool
138 max_servers:
139 description:
140 - Set number of allowable TCP small servers
141 - 1 to 2147483647
142 type: int
143 no_limit:
144 description: No limit on number of allowable TCP small servers
145 type: bool
146 type: dict
147 telnet_zeroidle:
148 description: Set TCP window 0 when connection is idle
149 type: bool
150 timestamps:
151 description: Timestamp debug/log messages
152 elements: dict
153 suboptions:
154 msg:
155 description: Timestamp log or debug messages
156 choices:
157 - debug
158 - log
159 type: str
160 enable:
161 description: Enable timestamp for the choosen message
162 type: bool
163 timestamp:
164 description: Timestamp with date and time or with system uptime
165 choices:
166 - datetime
167 - uptime
168 type: str
169 datetime_options:
170 description: Options for date and time timestamp
171 suboptions:
172 localtime:
173 description: Use local time zone for timestamps
174 type: bool
175 msec:
176 description: Include milliseconds in timestamp
177 type: bool
178 show_timezone:
179 description: Add time zone information to timestamp
180 type: bool
181 year:
182 description: Include year in timestam
183 type: bool
184 type: dict
185 type: list
186 udp_small_servers:
187 description:
188 - UDP small servers are servers (daemons, in Unix parlance) that run in the
189 router which are useful for diagnostics.
190 suboptions:
191 enable:
192 description: Enable small UDP servers (e.g., ECHO)
193 type: bool
194 max_servers:
195 description:
196 - Set number of allowable UDP small servers
197 - 1 to 2147483647
198 type: int
199 no_limit:
200 description: No limit on number of allowable UDP small servers
201 type: bool
202 type: dict
203 unsupported_transceiver:
204 description: enable support for third-party transceivers
205 type: bool
206 type: dict
207 running_config:
208 description:
209 - This option is used only with state I(parsed).
210 - The value of this option should be the output received from the IOS device by
211 executing the command B(show running-config | section ^service|^no service).
212 - The state I(parsed) reads the configuration from C(running_config) option and
213 transforms it into Ansible structured data as per the resource module's argspec
214 and the value is then returned in the I(parsed) key within the result.
215 type: str
216 state:
217 choices:
218 - merged
219 - replaced
220 - overridden
221 - deleted
222 - gathered
223 - rendered
224 - parsed
225 default: merged
226 description:
227 - The state the configuration should be left in.
228 - The module have declaratively similar behavior for replaced and overridden state.
229 - Refer to examples for more details.
230 type: str
231 """
232
233 EXAMPLES = """
234 # Using merged
235
236 # Before state:
237 # -------------
238
239 # router-ios#show running-config all | section ^service
240 # service slave-log
241 # service timestamps debug datetime msec
242 # service timestamps log datetime msec
243 # service private-config-encryption
244 # service prompt config
245 # service counters max age 0
246 # service dhcp
247 # service call-home
248 # service password-recovery
249
250 - name: Merge provided configuration with device configuration
251 cisco.ios.ios_service:
252 config:
253 tcp_keepalives_in: true
254 tcp_keepalives_out: true
255 timestamps:
256 - msg: debug
257 enable: true
258 timestamp: datetime
259 - msg: log
260 enable: true
261 timestamp: datetime
262 pad: false
263 password_encryption: true
264 state: merged
265
266 # Task Output
267 # -----------
268 #
269 # before:
270 # call_home: true
271 # counters: 0
272 # dhcp: true
273 # password_recovery: true
274 # private_config_encryption: true
275 # prompt: true
276 # slave_log: true
277 # timestamps:
278 # - datetime_options:
279 # msec: true
280 # msg: debug
281 # timestamp: datetime
282 # - datetime_options:
283 # msec: true
284 # msg: log
285 # timestamp: datetime
286 # commands:
287 # - service password-encryption
288 # - service tcp-keepalives-in
289 # - service tcp-keepalives-out
290 # after:
291 # call_home: true
292 # counters: 0
293 # dhcp: true
294 # password_encryption: true
295 # password_recovery: true
296 # private_config_encryption: true
297 # prompt: true
298 # slave_log: true
299 # tcp_keepalives_in: true
300 # tcp_keepalives_out: true
301 # timestamps:
302 # - datetime_options:
303 # msec: true
304 # msg: debug
305 # timestamp: datetime
306 # - datetime_options:
307 # msec: true
308 # msg: log
309 # timestamp: datetime
310
311 # After state:
312 # ------------
313
314 # router-ios#show running-config all | section ^service
315 # service slave-log
316 # service tcp-keepalives-in
317 # service tcp-keepalives-out
318 # service timestamps debug datetime msec
319 # service timestamps log datetime msec
320 # service password-encryption
321 # service private-config-encryption
322 # service prompt config
323 # service counters max age 0
324 # service dhcp
325 # service call-home
326 # service password-recovery
327
328 # Using replaced
329
330 # Before state:
331 # -------------
332
333 # router-ios#show running-config all | section ^service
334 # service slave-log
335 # service tcp-keepalives-in
336 # service tcp-keepalives-out
337 # service timestamps debug datetime msec
338 # service timestamps log datetime msec
339 # service password-encryption
340 # service private-config-encryption
341 # service prompt config
342 # service counters max age 0
343 # service dhcp
344 # service call-home
345 # service password-recovery
346
347 - name: Replaces device configuration of services with provided configuration
348 cisco.ios.ios_service:
349 config:
350 timestamps:
351 - msg: log
352 enable: true
353 timestamp: datetime
354 datetime_options:
355 localtime: true
356 msec: true
357 show_timezone: true
358 year: true
359 - msg: debug
360 enable: true
361 timestamp: datetime
362 pad: false
363 password_encryption: true
364 state: "replaced"
365
366 # Task Output
367 # -----------
368 #
369 # before:
370 # call_home: true
371 # counters: 0
372 # dhcp: true
373 # password_encryption: true
374 # password_recovery: true
375 # private_config_encryption: true
376 # prompt: true
377 # slave_log: true
378 # tcp_keepalives_in: true
379 # tcp_keepalives_out: true
380 # timestamps:
381 # - datetime_options:
382 # msec: true
383 # msg: debug
384 # timestamp: datetime
385 # - datetime_options:
386 # msec: true
387 # msg: log
388 # timestamp: datetime
389 # commands:
390 # - no service call-home
391 # - no service tcp-keepalives-in
392 # - no service tcp-keepalives-out
393 # - no service timestamps log
394 # - service timestamps log datetime msec localtime show-timezone year
395 # - no service timestamps debug
396 # - service timestamps debug datetime
397 # after:
398 # counters: 0
399 # dhcp: true
400 # password_encryption: true
401 # password_recovery: true
402 # private_config_encryption: true
403 # prompt: true
404 # slave_log: true
405 # timestamps:
406 # - msg: debug
407 # timestamp: datetime
408 # - datetime_options:
409 # localtime: true
410 # msec: true
411 # show_timezone: true
412 # year: true
413 # msg: log
414 # timestamp: datetime
415
416 # After state:
417 # ------------
418
419 # router-ios#show running-config all | section ^service
420 # service slave-log
421 # service timestamps debug datetime
422 # service timestamps log datetime msec localtime show-timezone year
423 # service password-encryption
424 # service private-config-encryption
425 # service prompt config
426 # service counters max age 0
427 # service dhcp
428 # service password-recovery
429
430 # Using Deleted
431
432 # Before state:
433 # -------------
434
435 # router-ios#show running-config all | section ^service
436 # service slave-log
437 # service timestamps debug datetime
438 # service timestamps log datetime msec localtime show-timezone year
439 # service password-encryption
440 # service private-config-encryption
441 # service prompt config
442 # service counters max age 0
443 # service dhcp
444 # service password-recovery
445
446 - name: "Delete service configuration and restore default configuration for some important service (those with a default value in module)"
447 cisco.ios.ios_service:
448 state: deleted
449
450 # Task Output
451 # -----------
452 #
453 # before:
454 # counters: 0
455 # dhcp: true
456 # password_encryption: true
457 # password_recovery: true
458 # private_config_encryption: true
459 # prompt: true
460 # slave_log: true
461 # timestamps:
462 # - msg: debug
463 # timestamp: datetime
464 # - datetime_options:
465 # localtime: true
466 # msec: true
467 # show_timezone: true
468 # year: true
469 # msg: log
470 # timestamp: datetime
471 # commands:
472 # - no service password-encryption
473 # - no service timestamps debug
474 # - no service timestamps log
475 # after:
476 # counters: 0
477 # dhcp: true
478 # password_recovery: true
479 # private_config_encryption: true
480 # prompt: true
481 # slave_log: true
482
483 # After state:
484 # ------------
485 #
486 # router-ios#show running-config all | section ^service
487 # service slave-log
488 # service private-config-encryption
489 # service prompt config
490 # service counters max age 0
491 # service dhcp
492 # service password-recovery
493
494 # Using gathered
495
496 # Before state:
497 # -------------
498 #
499 # router-ios#show running-config all | section ^service
500 # service slave-log
501 # service timestamps debug datetime
502 # service timestamps log datetime msec localtime show-timezone year
503 # service password-encryption
504 # service private-config-encryption
505 # service prompt config
506 # service counters max age 0
507 # service dhcp
508 # service password-recovery
509
510 - name: Gather facts of interfaces
511 cisco.ios.ios_service:
512 config:
513 state: gathered
514
515 # Task Output
516 # -----------
517 #
518 # gathered:
519 # counters: 0
520 # dhcp: true
521 # password_encryption: true
522 # password_recovery: true
523 # private_config_encryption: true
524 # prompt: true
525 # slave_log: true
526 # timestamps:
527 # - msg: debug
528 # timestamp: datetime
529 # - datetime_options:
530 # localtime: true
531 # msec: true
532 # show_timezone: true
533 # year: true
534 # msg: log
535 # timestamp: datetime
536
537 # Using rendered
538
539 - name: Render the commands for provided configuration
540 cisco.ios.ios_service:
541 config:
542 timestamps:
543 - msg: log
544 enable: true
545 timestamp: datetime
546 datetime_options:
547 localtime: true
548 msec: true
549 show_timezone: true
550 year: true
551 - msg: debug
552 enable: true
553 timestamp: datetime
554 pad: false
555 password_encryption: true
556 state: rendered
557
558 # ·Task·Output
559 # -----------
560 #
561 # rendered:
562 # - service dhcp
563 # - service password-encryption
564 # - service password-recovery
565 # - service prompt config
566 # - service slave-log
567 # - service timestamps log datetime msec localtime show-timezone year
568 # - service timestamps debug datetime
569
570 # Using parsed
571
572 # File: parsed.cfg
573 # ----------------
574 #
575 # no service pad
576 # service password-encryption
577 # service tcp-keepalives-in
578 # service tcp-keepalives-out
579 # service timestamps debug datetime msec localtime show-timezone year
580 # service timestamps log datetime msec localtime show-timezone year
581 # service counters max age 5
582
583 - name: Parse the provided configuration
584 cisco.ios.ios_service:
585 running_config: "{{ lookup('file', 'parsed.cfg') }}"
586 state: parsed
587
588 # Task Output
589 # -----------
590 #
591 # parsed:
592 # counters: 5
593 # dhcp: true
594 # password_encryption: true
595 # password_recovery: true
596 # prompt: true
597 # slave_log: true
598 # tcp_keepalives_in: true
599 # tcp_keepalives_out: true
600 # timestamps:
601 # - datetime_options:
602 # localtime: true
603 # msec: true
604 # show_timezone: true
605 # year: true
606 # msg: debug
607 # timestamp: datetime
608 # - datetime_options:
609 # localtime: true
610 # msec: true
611 # show_timezone: true
612 # year: true
613 # msg: log
614 # timestamp: datetime
615 """
616
617 RETURN = """
618 before:
619 description: The configuration prior to the module execution.
620 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
621 type: dict
622 sample: >
623 This output will always be in the same format as the
624 module argspec.
625 after:
626 description: The resulting configuration after module execution.
627 returned: when changed
628 type: dict
629 sample: >
630 This output will always be in the same format as the
631 module argspec.
632 commands:
633 description: The set of commands pushed to the remote device.
634 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
635 type: list
636 sample:
637 - no service config
638 - service tcp-keepalives-in
639 - service tcp-keepalives-out
640 rendered:
641 description: The provided configuration in the task rendered in device-native format (offline).
642 returned: when I(state) is C(rendered)
643 type: list
644 sample:
645 - service dhcp
646 - service password-encryption
647 - service password-recovery
648 - service prompt config
649 - service slave-log
650 gathered:
651 description: Facts about the network resource gathered from the remote device as structured data.
652 returned: when I(state) is C(gathered)
653 type: list
654 sample: >
655 This output will always be in the same format as the
656 module argspec.
657 parsed:
658 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
659 returned: when I(state) is C(parsed)
660 type: list
661 sample: >
662 This output will always be in the same format as the
663 module argspec.
664 """
665
666 from ansible.module_utils.basic import AnsibleModule
667
668 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.service.service import (
669 ServiceArgs,
670 )
671 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.service.service import (
672 Service,
673 )
674
675
676 def main():
677 """
678 Main entry point for module execution
679
680 :returns: the result form module invocation
681 """
682 module = AnsibleModule(
683 argument_spec=ServiceArgs.argument_spec,
684 mutually_exclusive=[["config", "running_config"]],
685 required_if=[
686 ["state", "merged", ["config"]],
687 ["state", "replaced", ["config"]],
688 ["state", "overridden", ["config"]],
689 ["state", "rendered", ["config"]],
690 ["state", "parsed", ["running_config"]],
691 ],
692 supports_check_mode=True,
693 )
694
695 result = Service(module).execute_module()
696 module.exit_json(**result)
697
698
699 if __name__ == "__main__":
700 main()