From 24d112fc605008d9de1a9bbb3424f67fdc0371a2 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Mon, 13 Aug 2018 11:02:43 +0530 Subject: [PATCH] Fix cli_command junos test failure and update doc (#44021) * Fix cli_command junos test failure and update doc * Fix cli_command module integration test failure for junos * Update cli_command module doc for prompt and config command run scenario's * Update cli_command module doc --- .../modules/network/cli/cli_command.py | 11 +++++ .../junos_command/tests/cli/cli_commmand.yaml | 44 ++++++++++--------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/lib/ansible/modules/network/cli/cli_command.py b/lib/ansible/modules/network/cli/cli_command.py index 7c2450b56f..778b397c0f 100644 --- a/lib/ansible/modules/network/cli/cli_command.py +++ b/lib/ansible/modules/network/cli/cli_command.py @@ -57,6 +57,17 @@ EXAMPLES = """ 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 = """ diff --git a/test/integration/targets/junos_command/tests/cli/cli_commmand.yaml b/test/integration/targets/junos_command/tests/cli/cli_commmand.yaml index b23b81c462..b08ac1cd7d 100644 --- a/test/integration/targets/junos_command/tests/cli/cli_commmand.yaml +++ b/test/integration/targets/junos_command/tests/cli/cli_commmand.yaml @@ -2,28 +2,32 @@ - debug: msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}" -- name: get output for single command - cli_command: - commands: - - show version - register: result +- block: + - name: get output for single command + cli_command: + command: show version + register: result -- assert: - that: - - "result.changed == false" - - "result.stdout is defined" + - assert: + that: + - "result.changed == false" + - "result.stdout is defined" -- name: get output for multiple commands - cli_command: - commands: - - show version - - show interfaces - register: result + - name: test with prompt and answer + cli_command: + command: "{{ item }}" + prompt: + - "Exit with uncommitted changes" + answer: yes + loop: + - configure + - set system syslog file test any any + - exit + register: result -- assert: - that: - - "result.changed == false" - - "result.stdout is defined" - - "result.stdout | length == 2" + - assert: + that: + - "result.changed == false" + when: ansible_connection == 'network_cli' - debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"