cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
8590
Views
10
Helpful
14
Replies
jan.murin
Beginner

ansible upgrade ios

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

1 ACCEPTED SOLUTION

Accepted Solutions
dss1
Beginner

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.

View solution in original post

14 REPLIES 14
sofiane7704
Beginner

Did you check if you had enough memory ?

Hi,

Yeap, I checked that. I have no problem to upload the image manually.

looks to me like the FTP server is hanging. Did you try a different FTP server ? 

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.

dss1
Beginner

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.

View solution in original post

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.

 

My fault,

It works!

Thanks a lot dss1

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 

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

Jose Mauro
Beginner

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"

 

allan.maseghe
Beginner

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

 

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."
}

 

 

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
vikram4
Beginner

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)

Content for Community-Ad