Remove unnecessary features from cli_command (#43829)

* Remove wait_for & associated params

* Upgrade command dict to top-level, remove more wait_for accessories

* We don't need all this anymore

* Update docs

* Update tests to new argspec

* Be a little more explicit about sendonly

Also remove reference to the word provider.

* Add example of prompt and answer
This commit is contained in:
Nathaniel Case
2018-08-09 12:46:38 -04:00
committed by GitHub
parent 32eab149b6
commit 0f554f9208
13 changed files with 205 additions and 298 deletions

View File

@@ -2,10 +2,41 @@
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- name: get output for single command
cli_command:
command: show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: send invalid command
cli_command:
command: 'show foo'
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- name: get output in JSON format
cli_command:
command: show version | json
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.json is defined"
- name: command that does require become (should fail)
cli_command:
commands:
- show running-config
command: show running-config
become: no
ignore_errors: yes
register: result
@@ -15,28 +46,4 @@
- 'result.failed == true'
- '"privileged mode required" in result.msg'
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interfaces
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View File

@@ -4,8 +4,7 @@
- name: get output for single command
cli_command:
commands:
- show version
command: show version
register: result
- assert:
@@ -13,17 +12,15 @@
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
- name: send invalid command
cli_command:
commands:
- show version
- show interfaces
command: 'show foo'
register: result
ignore_errors: yes
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View File

@@ -1,32 +0,0 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- block:
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interfaces
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
when: ansible_connection == 'network_cli'
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View File

@@ -0,0 +1,46 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- name: get output for single command
cli_command:
command: show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: send invalid command
cli_command:
command: 'show foo'
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- block:
- name: Run command with prompt
cli_command:
command: 'copy running-config harddisk:ansible_tmp.txt'
prompt: 'Destination file name \(control-c to abort\)\: \[\/ansible_tmp.txt\]\?'
answer: 'ansible_tmp.txt'
register: result
- assert:
that:
- "result.stdout is defined"
- "'ansible_tmp' in result.stdout[0]"
always:
- name: Remove copied file
cli_command:
command: 'delete harddisk:ansible_tmp.txt'
prompt: 'Delete harddisk\:ansible_tmp\.txt\[confirm\]'
answer: "\r\n"
ignore_errors: yes
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View File

@@ -1,32 +0,0 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- block:
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interfaces
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
when: ansible_connection == 'network_cli'
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View File

@@ -2,3 +2,4 @@
- { include: netconf_xml.yaml, tags: ['netconf', 'xml'] }
- { include: netconf_text.yaml, tags: ['netconf', 'text'] }
- { include: netconf_json.yaml, tags: ['netconf', 'json'] }
- { include: cli.yaml, tags: ['cli'] }

View File

@@ -1,3 +1,2 @@
---
- { include: netconf.yaml, tags: ['netconf'] }
- { include: cli.yaml, tags: ['cli'] }

View File

@@ -0,0 +1,26 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- name: get output for single command
cli_command:
command: show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: send invalid command
cli_command:
command: 'show foo'
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View File

@@ -1,32 +0,0 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- block:
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interface
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
when: ansible_connection == 'network_cli'
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View File

@@ -0,0 +1,26 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- name: get output for single command
cli_command:
command: show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: send invalid command
cli_command:
command: 'show foo'
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"