Documentation

cli_command - Run a cli command on cli-based network devices

New in version 2.7.

Synopsis

  • Sends a command to a network device and returns the result read from the device.

Parameters

Parameter Choices/Defaults Comments
answer
The answer to reply with if prompt is matched.
command
required
The command to send to the remote network device. The resulting output from the command is returned, unless sendonly is set.
prompt
A single regex pattern or a sequence of patterns to evaluate the expected prompt from command.
sendonly
bool
    Choices:
  • no ←
  • yes
The boolean value, that when set to true will send command to the device but not wait for a result.

Examples

- name: run show version on remote devices
  cli_command:
    command: show version

- name: run command with json formatted output
  cli_command:
    command: show version | json

- name: run command expecting user confirmation
  cli_command:
    command: commit replace
    prompt: This commit will replace or remove the entire running configuration
    answer: yes

- name: run config mode command and handle prompt/answer
  cli_command:
    command: "{{ item }}"
    prompt:
      - "Exit with uncommitted changes"
    answer: yes
  loop:
    - configure
    - set system syslog file test any any
    - exit

Return Values

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

Key Returned Description
json
dict
when the device response is valid JSON
A dictionary representing a JSON-formatted response

Sample:
{ "architecture": "i386", "bootupTimestamp": 1532649700.56, "modelName": "vEOS", "version": "4.15.9M" [...] }
stdout
string
when sendonly is false
The response from the command

Sample:
Version: VyOS 1.1.7[...]


Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Support

For more information about Red Hat’s support of this module, please refer to this Knowledge Base article

Author

  • Nathaniel Case (@qalthos)

Hint

If you notice any issues in this documentation you can edit this document to improve it.