cisco.radkit.exec_and_wait module – Executes commands on devices using RADKit and handles interactive prompts
Note
This module is part of the cisco.radkit collection (version 2.0.0).
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install git+https://wwwin-github.cisco.com/scdozier/cisco.radkit-ansible.git
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: cisco.radkit.exec_and_wait
.
New in cisco.radkit 1.7.61
Synopsis
This module runs commands on specified devices using RADKit, handling interactive prompts with pexpect.
Enhanced with retry logic, progress monitoring, and better error handling.
Requirements
The below requirements are needed on the host that executes this module.
radkit
pexpect
Parameters
Parameter |
Comments |
---|---|
List of answers corresponding to the expected prompts. |
|
Alternate path to client ca cert for RADKIT If the value is not specified in the task, the value of environment variable RADKIT_ANSIBLE_CLIENT_CA_PATH will be used instead. |
|
Alternate path to client cert for RADKIT If the value is not specified in the task, the value of environment variable RADKIT_ANSIBLE_CLIENT_CERT_PATH will be used instead. |
|
Client certificate password in base64 If the value is not specified in the task, the value of environment variable RADKIT_ANSIBLE_CLIENT_PRIVATE_KEY_PASSWORD_BASE64 will be used instead. |
|
Alternate path to client key for RADKIT If the value is not specified in the task, the value of environment variable RADKIT_ANSIBLE_CLIENT_KEY_PATH will be used instead. |
|
Maximum number of retries for command execution failures. Default: |
|
Time in seconds to wait for a command to complete. Default: |
|
List of commands to execute on the device. |
|
Continue processing other devices if one device fails. Choices:
|
|
Delay in seconds before performing a final check on the device state. Default: |
|
Hostname or IP address of the device as it appears in the RADKit inventory. Use either device_name or device_host. |
|
Name of the device as it appears in the RADKit inventory. Use either device_name or device_host. |
|
Identity to authentiate with RADKit (xxxx@cisco.com). If the value is not specified in the task, the value of environment variable RADKIT_ANSIBLE_IDENTITY will be used instead. |
|
List of expected prompts to handle interactively. |
|
Custom command to test device responsiveness during recovery. Default: |
|
Maximum time in seconds to wait after sending the commands before checking the device state. |
|
Radkit service serial If the value is not specified in the task, the value of environment variable RADKIT_ANSIBLE_SERVICE_SERIAL will be used instead. |
|
Time in seconds to wait after sending an answer to a prompt for performance tuning. Default: |
|
Time in seconds to wait between sending commands for performance tuning. Default: |
Examples
- name: Simple config mode change (backwards compatible)
cisco.radkit.exec_and_wait:
device_name: "{{ inventory_hostname }}"
commands:
- "config t"
prompts:
- ".*"
answers:
- "exit
"
seconds_to_wait: 10
delay_before_check: 2
command_timeout: 4
register: config_result
delegate_to: localhost
# Uses default recovery_test_command: "
" for immediate recovery
- name: Configuration change with explicit exit
cisco.radkit.exec_and_wait:
device_name: "{{ inventory_hostname }}"
commands:
- "configure terminal"
- "interface loopback 999"
- "description Test interface"
- "exit"
- "exit"
prompts: []
answers: []
seconds_to_wait: 30
delay_before_check: 2
register: config_result
delegate_to: localhost
# Uses default recovery_test_command: "
" for prompt check only
- name: Execute show commands safely
cisco.radkit.exec_and_wait:
device_name: "{{ inventory_hostname }}"
commands:
- "show version"
- "show clock"
- "show ip interface brief"
prompts: []
answers: []
seconds_to_wait: 30
delay_before_check: 2
command_retries: 2
recovery_test_command: "show clock" # Verify with actual command
register: show_commands
delegate_to: localhost
- name: Test network connectivity (execution test, not success test)
cisco.radkit.exec_and_wait:
device_name: "{{ inventory_hostname }}"
commands:
- "ping 8.8.8.8 repeat 2"
prompts: []
answers: []
seconds_to_wait: 60
delay_before_check: 5
recovery_test_command: "show clock" # Verify device is responsive
register: ping_test
delegate_to: localhost
# Note: This tests command execution, ping may fail due to network policies
- name: Reload Router and Wait Until Available
cisco.radkit.exec_and_wait:
device_name: "{{ inventory_hostname }}"
commands:
- "reload"
prompts:
- ".*yes/no].*"
- ".*confirm].*"
answers:
- "yes
"
- "
"
seconds_to_wait: 300 # total time to wait for reload
delay_before_check: 10 # Delay before checking terminal
command_retries: 1
# Uses default recovery_test_command: "
" - only check prompt after reboot
register: reload_result
delegate_to: localhost
- name: Reset the Connection
# The connection must be reset to allow Ansible to poll the router for connectivity
meta: reset_connection
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Device name (for single device compatibility) Returned: success |
|
Results for each device processed Returned: always |
|
Number of recovery attempts Returned: success |
|
Name of the device Returned: success |
|
List of commands executed Returned: success |
|
Time taken for device recovery Returned: success |
|
Execution status (SUCCESS/FAILED) Returned: success |
|
Command output Returned: success |
|
Commands executed (for single device compatibility) Returned: success |
|
Output of commands (for single device compatibility) Returned: success |
|
Summary of execution across all devices Returned: always |
|
Number of devices that failed Returned: success |
|
Number of devices that succeeded Returned: success |
|
Total number of devices processed Returned: success |