10-19-2018 01:05 AM
Hi,
I am playing a little with the ansible and currently I am trying to upgrade the IOS on the switches.
The whole process consists of several task:
1. Check the current version
2. Copy new image to the switch
3. Set the boot image
4. Reboot
5. Check version again
The main problem I am not able to solve now is the second step (Copy new image to the switch).
I am using the ios_command module and the task looks like this:
- name: Copy image to device
ios_command:
commands:
- command: "copy ftp://username:password@server/image.bin flash:"
prompt: Destination filename \[image.bin\]?
answer: "\r"
The problem is that the FTP download is started but is shutdowned after few seconds. I tried to increase the command timeout and also the persistent_connection without success.
Thanks for any advice.
Regards
Solved! Go to Solution.
12-18-2018 05:43 AM
Do you want to try:
- name: COPY_FTP_IMAGE
cli_command:
command: 'copy ftp flash:'
check_all: True
prompt:
- 'Address or name of remote host'
- 'Source filename'
- 'Destination filename'
answer:
- '<ip address ftp server>'
- '<image file.bin>'
- '<image file.bin'
vars:
ansible_command_timeout: 1200
The timeout value depends on image file size and connection throughput.
10-19-2018 05:38 AM
Did you check if you had enough memory ?
10-19-2018 07:09 AM
Hi,
Yeap, I checked that. I have no problem to upload the image manually.
10-19-2018 07:19 AM - edited 10-19-2018 08:22 AM
looks to me like the FTP server is hanging. Did you try a different FTP server ?
10-19-2018 12:32 PM
If i type the command manually on the switch, everything is working ax expected. However when I push the command by ansible, the ftp transmission is stopped after few seconds. For me, it looks like the ansible is not waiting till the transmission ends, stops the process and pushes next command.
12-18-2018 05:43 AM
Do you want to try:
- name: COPY_FTP_IMAGE
cli_command:
command: 'copy ftp flash:'
check_all: True
prompt:
- 'Address or name of remote host'
- 'Source filename'
- 'Destination filename'
answer:
- '<ip address ftp server>'
- '<image file.bin>'
- '<image file.bin'
vars:
ansible_command_timeout: 1200
The timeout value depends on image file size and connection throughput.
12-19-2018 07:25 AM
Hi dss1,
Thanks for advice.
Still the same problem. The FTP session is closed after a while (sometimes after few seconds, sometimes after 1-2 minutes) and never correctly finished. As the disconnect time differs, I don't think it's relevant to the timeout value I have set in ansible.
12-19-2018 07:55 AM
My fault,
It works!
Thanks a lot dss1
04-07-2020 10:11 PM
How did that timeout error worked, i have increased the timeout to 2000 seconds, even after doing that it throws the timeout error aafter 2000 seconds, Kindly suggest
07-09-2019 09:11 AM
Hi dss1,
Do you know the max timeout value that can be used here?
Also, do you have the yml syntax to copy an image from the ansible node to remote ios device?
Regards, mk
07-09-2019 08:01 PM
you can try that with SCP.
command: "scp system-image-filename.bin {{inventory_hostname}}:/system-image-filename.bin"
Source:
https://gdykeman.github.io/2018/06/26/ios-upgrades/
P.S. SCP needs to bem enabeld
"ip scp server enable"
04-26-2020 06:15 PM
Not sure if this was answered.
You can check out the script I wrote for my day to day work here.
https://github.com/254In61/ciscoIosUpgrade
06-03-2020 07:18 AM
I am trying to do this also and using the Ansible Net_Put module
It still uses SCP but I am hitting a command timeout also?
This is the playbook section
## Copy software to target device
- name: Copy Software Image to target device
net_put:
src: "~/network-programmability/images/c2960-lanbasek9-mz.122-55.SE12.bin"
dest: "flash:c2960-lanbasek9-mz.122-55.SE12.bin"
I have enabled SCP on the switch
ip scp server enable
However it fails with
fatal: [192.168.1.250]: FAILED! => {
"changed": true,
"destination": "flash:c2960-lanbasek9-mz.122-55.SE12.bin",
"msg": "Exception received : command timeout triggered, timeout value is 30 secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide."
}
08-28-2020 01:43 PM
Use the ansible_command_timeout option.
- name: COPY FILE TO DEVICE net_put: src: images/{{ image }} protocol: scp dest : bootflash:/{{ image }} vars: ansible_command_timeout: 10000
03-11-2021 02:17 PM
I am facing problem for only 1 step of this activity.
Problem: In a stacked switch, 'ansible_net_filesystems_info' of ios_facts module only shows total and free space of master switch. It doesn't show space of member switch. But I need to write a script that will check for certain amount of free space in EVERY member switch before copying ios image.
A workaround idea i have is to execute below command and make ansible store free space of every member switch in a custom variable. Then is it possible to somehow tell ansible to check if the value in variable (free space value listed below) should be higher than 50 MB before copying image?
Or do you have any other suggestion?
sh flash2: | i bytes free
122185728 bytes total (9308672 bytes free)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide