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

answers

list / elements=string

List of answers corresponding to the expected prompts.

client_ca_path

string

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.

client_cert_path

string

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_key_password_b64

aliases: radkit_client_private_key_password_base64

string / required

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.

client_key_path

string

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.

command_retries

integer

Maximum number of retries for command execution failures.

Default: 1

command_timeout

integer

Time in seconds to wait for a command to complete.

Default: 15

commands

list / elements=string

List of commands to execute on the device.

continue_on_device_failure

boolean

Continue processing other devices if one device fails.

Choices:

  • false ← (default)

  • true

delay_before_check

integer

Delay in seconds before performing a final check on the device state.

Default: 10

device_host

string

Hostname or IP address of the device as it appears in the RADKit inventory. Use either device_name or device_host.

device_name

string

Name of the device as it appears in the RADKit inventory. Use either device_name or device_host.

identity

aliases: radkit_identity

string / required

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.

prompts

list / elements=string

List of expected prompts to handle interactively.

recovery_test_command

string

Custom command to test device responsiveness during recovery.

Default: " "

seconds_to_wait

integer / required

Maximum time in seconds to wait after sending the commands before checking the device state.

service_serial

aliases: radkit_serial, radkit_service_serial

string / required

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.

wait_after_answer

float

Time in seconds to wait after sending an answer to a prompt for performance tuning.

Default: 0.5

wait_between_commands

float

Time in seconds to wait between sending commands for performance tuning.

Default: 0.5

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

string

Device name (for single device compatibility)

Returned: success

devices

dictionary

Results for each device processed

Returned: always

attempt_count

integer

Number of recovery attempts

Returned: success

device_name

string

Name of the device

Returned: success

executed_commands

list / elements=string

List of commands executed

Returned: success

recovery_time

float

Time taken for device recovery

Returned: success

status

string

Execution status (SUCCESS/FAILED)

Returned: success

stdout

string

Command output

Returned: success

executed_commands

list / elements=string

Commands executed (for single device compatibility)

Returned: success

stdout

string

Output of commands (for single device compatibility)

Returned: success

summary

dictionary

Summary of execution across all devices

Returned: always

failed_devices

integer

Number of devices that failed

Returned: success

successful_devices

integer

Number of devices that succeeded

Returned: success

total_devices

integer

Total number of devices processed

Returned: success

Authors

  • Scott Dozier (@scdozier)