�
�Udac @` s� d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d
Z d d l
m Z d d l m
Z
d d
l m Z m Z d � Z e d k r� e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust networkt supported_bysb
---
module: cli_command
version_added: "2.7"
author: "Nathaniel Case (@Qalthos)"
short_description: Run a cli command on cli-based network devices
description:
- Sends a command to a network device and returns the result read from the device.
extends_documentation_fragment: network_agnostic
options:
command:
description:
- The command to send to the remote network device. The resulting output
from the command is returned, unless I(sendonly) is set.
required: true
prompt:
description:
- A single regex pattern or a sequence of patterns to evaluate the expected
prompt from I(command).
required: false
type: list
answer:
description:
- The answer to reply with if I(prompt) is matched. The value can be a single answer
or a list of answer for multiple prompts. In case the command execution results in
multiple prompts the sequence of the prompt and excepted answer should be in same order.
required: false
type: list
sendonly:
description:
- The boolean value, that when set to true will send I(command) to the
device but not wait for a result.
type: bool
default: false
required: false
newline:
description:
- The boolean value, that when set to false will send I(answer) to the
device without a trailing newline.
type: bool
default: true
required: false
version_added: 2.9
check_all:
description:
- By default if any one of the prompts mentioned in C(prompt) option is matched it won't check
for other prompts. This boolean flag, that when set to I(True) will check for all the prompts
mentioned in C(prompt) option in the given order. If the option is set to I(True) all the prompts
should be received from remote host if not it will result in timeout.
type: bool
default: false
sm
- 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 command expecting user confirmation
cli_command:
command: show interface summary
prompt: Press any key to continue
answer: y
newline: false
- name: run config mode command and handle prompt/answer
cli_command:
command: "{{ item }}"
prompt:
- "Exit with uncommitted changes"
answer: 'y'
loop:
- configure
- set system syslog file test any any
- exit
- name: multiple prompt, multiple answer (mandatory check for all prompts)
cli_command:
command: "copy sftp sftp://user@host//user/test.img"
check_all: True
prompt:
- "Confirm download operation"
- "Password"
- "Do you want to change that to the standby image"
answer:
- 'y'
- <password>
- 'y'
s�
stdout:
description: The response from the command
returned: when sendonly is false
type: str
sample: 'Version: VyOS 1.1.7[...]'
json:
description: A dictionary representing a JSON-formatted response
returned: when the device response is valid JSON
type: dict
sample: |
{
"architecture": "i386",
"bootupTimestamp": 1532649700.56,
"modelName": "vEOS",
"version": "4.15.9M"
[...]
}
( t to_text( t
AnsibleModule( t
Connectiont ConnectionErrorc C` s� t d t d d d t � d t d d d t � d t d d d t � d t d d d
t d t � d t d d d
t d t � d t d d d
t d t � � } d d g g } t d
| d | d t � } | j r| j d j d � r| j d d | j d � n t � } i t d 6| d 6} t | j
� } d } y | j | j � } Wn/ t k
rz} | j d t
| d d �� n X| j d s�y | j | � | d <Wn t k
r�n X| j i | d 6� n | j | � d S( s% entry point for module execution
t commandt typet strt requiredt promptt listt answert newlinet boolt defaultt sendonlyt check_allt
argument_spect required_togethert supports_check_modet showt msgsH Only show commands are supported when using check_mode, not executing %st changedt warningst t errorst surrogate_then_replacet jsont stdoutN( t dictt Truet FalseR t
check_modet paramst
startswitht fail_jsonR R
t _socket_patht getR R t from_jsont
ValueErrort updatet exit_json( R R t moduleR t resultt
connectiont responset exc( ( sK /usr/lib/python2.7/site-packages/ansible/modules/network/cli/cli_command.pyt main� s<