cisco.radkit.command module – Execute commands on network devices via Cisco RADKit

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.command.

New in cisco.radkit 0.2.0

Synopsis

  • Executes one or more commands on network devices managed by Cisco RADKit

  • Supports execution on single devices or multiple devices using filter patterns

  • Returns structured command output with execution status and optional prompt removal

  • Provides comprehensive error handling and logging for troubleshooting

Requirements

The below requirements are needed on the host that executes this module.

  • cisco-radkit-client

Parameters

Parameter

Comments

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.

commands

aliases: command

list / elements=string / required

List of commands to execute on the target device(s)

Each command will be executed sequentially

Commands should be valid for the target device OS

device_name

string

Name of a specific device as it appears in RADKit inventory

Mutually exclusive with filter_pattern and filter_attr

exec_timeout

integer

Maximum time in seconds to wait for individual command execution

Set to 0 for no timeout (default behavior)

Can be set via environment variable RADKIT_ANSIBLE_EXEC_TIMEOUT

Default: 0

filter_attr

string

Inventory attribute to match against the filter_pattern

Common values include ‘name’, ‘hostname’, ‘ip_address’

Must be used together with filter_pattern

filter_pattern

string

Pattern to match against RADKit inventory for multi-device operations

Use glob-style patterns (e.g., ‘router*’, ‘switch-*’)

Must be used together with filter_attr

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.

remove_prompts

boolean

Remove first and last lines from command output (typically CLI prompts)

Helps clean up output for parsing and display

Choices:

  • false

  • true ← (default)

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_timeout

integer

Maximum time in seconds to wait for RADKit task completion

Set to 0 for no timeout (default behavior)

Can be set via environment variable RADKIT_ANSIBLE_WAIT_TIMEOUT

Default: 0

Examples

# Execute a single command on a specific device
- name: Get version information from router-01
  cisco.radkit.command:
    device_name: router-01
    commands: show version
  register: version_output
  delegate_to: localhost

# Execute multiple commands on a single device
- name: Get system information from router-01
  cisco.radkit.command:
    device_name: router-01
    commands:
      - show version
      - show ip interface brief
      - show running-config | include hostname
  register: system_info
  delegate_to: localhost

# Execute commands on multiple devices using filter pattern
- name: Get version from all routers
  cisco.radkit.command:
    filter_attr: name
    filter_pattern: router*
    commands: show version
  register: all_versions
  delegate_to: localhost

# Execute with custom timeouts and without prompt removal
- name: Long running command with custom settings
  cisco.radkit.command:
    device_name: core-switch-01
    commands: show tech-support
    exec_timeout: 300
    wait_timeout: 600
    remove_prompts: false
  register: tech_support
  delegate_to: localhost

# Display command output
- name: Show command results
  debug:
    msg: "{{ version_output.stdout }}"

# Process multiple device results
- name: Process results from multiple devices
  debug:
    msg: "Device {{ item.device_name }} version: {{ item.stdout | regex_search('Version ([0-9.]+)', '\1') | first }}"
  loop: "{{ all_versions.ansible_module_results }}"
  when: all_versions.ansible_module_results is defined

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

ansible_module_results

list / elements=dictionary

List of results when executing on multiple devices or multiple commands

Each item contains device_name, command, stdout, exec_status, and exec_status_message

Returned: when multiple devices or commands are involved

Sample: [{"command": "show version", "device_name": "router-01", "exec_status": "SUCCESS", "exec_status_message": "Command executed successfully", "stdout": "Cisco IOS XE Software..."}]

changed

boolean

Whether any changes were made (always false for command execution)

Returned: always

Sample: false

command

string

The command that was executed

Returned: success

Sample: "show version"

device_name

string

Name of the device where the command was executed

Returned: success

Sample: "router-01"

exec_status

string

Execution status from RADKit

Returned: always

Sample: "SUCCESS"

exec_status_message

string

Detailed status message from RADKit

Returned: always

Sample: "Command executed successfully"

stdout

string

Command output from the device

Returned: success

Sample: "Cisco IOS XE Software, Version 16.09.08..."

Authors

  • Scott Dozier (@scdozier)