Dynamic ios command prompts for cisco switches + output message.
- Hello Team,
I am running ios_command as ansible tasks, which basically copying the files from remote machine onto local cisco switch and have observed that while executing the copy command from cli (directly on cisco) the prompts are random and also sometimes randomly shown in ansible tasks.
Note: Twice i am being able to successfully test the copy file tasks, but later after removing / deleting the file on cisco switch and again running the copy tasks the prompts has changed.
Need your help for below queries:
- How to handle the dynamic prompts in ansible tasks.
- In the output below, the debug output is truncating the full message, need to show completed prompts / output
Cisco cli command:
#copy scp://<IP address of remote host>/cat9k_iosxe.17.09.07.SPA.bin flash: vrf Mgmt-vrf
Address or name of remote host --> <prompt initially asked>
Source username ? --> <usually asked>
Source filename ? --> <random prompts>
Destination filename ? --> <usually asked>
Password: --> <always asked>
Ansible code:
- name: Execute SCP copy command
cisco.ios.ios_command:
commands:
- command: "copy scp://{{ remote_host }}/{{ new_file }} flash:{{ new_file }} vrf Mgmt-vrf"
prompt:
- 'Address or name of remote host \[{{ remote_host }}\]\?'
- 'Source username \[{{ source_username }}\]\?'
- 'Source filename \[{{ new_file }}\]\?'
- 'Destination filename \[{{ new_file }}\]\?'
- 'Password:'
answer:
- '' ##"{{ remote_host }}" # Address
- '' ##"{{ source_username }}" # Correct username
- '' ##"{{ new_file }}" # Correct source filename
- '' ##"{{ new_file }}" # Correct destination filename
- "{{ srv_net_password }}" ## Correct password
check_all: True
wait_for:
- result[0] contains "bytes copied"
match: any
register: sftp_output
Ansible output:
TASK [switch-upgrade : Execute SCP copy command] *******************************
fatal: [nwswitch]: FAILED! => changed=false
msg: |-
rf Mgmt-vrf
Source username [service-net.ansible]?
Destination filename [cat9k_iosxe.17.09.07.SPA.bin]?
Password:
% Authentication failed.
%Error opening scp://*@10.21.11.9/cat9k_iosxe.17.09.07.SPA.bin (Permission denied)
nwslab-lon2-csw-0601#
...ignoring