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. |
Examples
- 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
register: ping_test
# Note: This tests command execution, ping may fail due to network policies
- 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
register: show_commands
- name: Reload Router and Wait Until Available by using ansible_host
cisco.radkit.exec_and_wait:
#device_name: "{{inventory_hostname}}"
device_host: "{{ansible_host}}"
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
recovery_test_command: "show clock"
register: reload_result
- name: Reload Router and Wait Until Available by using inventory_hostname
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
continue_on_device_failure: false
register: reload_result
- name: Configuration change with confirmation
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
recovery_test_command: "show running-config interface loopback 999"
register: config_result
- 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 |