# Ansible upgrade cisco switch stack firmware

**URL:** <https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763>\
**Category:** Ansible Project\
**Created:** [March 11, 2021, 5:17am UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763 "2021-03-11T05:17:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chr00ted](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chr00ted/32/2188_2.png) [@chr00ted](https://forum.ansible.com/u/chr00ted)\
**Post date:** [March 11, 2021, 5:17am UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763/1 "2021-03-11T05:17:13Z")

</div>

I’m trying to update a cisco switch stack with ansible and I would like to use the archive command, but that doesn’t work with .bin files.

For the 9200 series switches, I can only download .bin files.

I have tried:

ios\_command:  
commands:

- command: install add file flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin  
wait\_for: result[0] contains SUCCESS

That isn’t working for me either. I may need to enter a timeout as well.

Please let me know if you have any suggestions. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![chr00ted](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chr00ted/32/2188_2.png) [@chr00ted](https://forum.ansible.com/u/chr00ted)\
**Post date:** [March 11, 2021, 3:06pm UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763/2 "2021-03-11T15:06:54Z")

</div>

I ended up running the following manually. I just need a way for ansible to wait for certain prompts and allow the process to complete without ansible failing the job. Again, any suggestions would be appreciated…

Here is the manual command ran:

9200L-24T-4G-E\_2#$ **install add file flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin activate commit**  
install\_add\_activate\_commit: START Thu Mar 11 08:43:55 EST 2021

System configuration has been modified.  
Press Yes(y) to save the configuration and proceed.  
Press No(n) for proceeding without saving the configuration.  
Press Quit(q) to exit, you may save configuration and re-enter the command. **[y/n/q]y**  
Modified configuration has been saved  
Mar 11 08:44:10.982 %INSTALL-5-INSTALL\_START\_INFO: R0/0: install\_engine: Started install one-shot flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin  
install\_add\_activate\_commit: Adding PACKAGE  
install\_add\_activate\_commit: Checking whether new add is allowed …

— Starting initial file syncing —  
[1]: Copying flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin from switch 1 to switch 2  
[2]: Finished copying to switch 2  
Info: Finished copying flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin to the selected switch(es)  
Finished initial file syncing

— Starting Add —  
Performing Add on all members  
[1] Add package(s) on switch 1  
[1] Finished Add on switch 1  
[2] Add package(s) on switch 2  
[2] Finished Add on switch 2  
Checking status of Add on [1 2]  
Add: Passed on [1 2]  
Finished Add

Image added. Version: 16.12.4.0.4480  
install\_add\_activate\_commit: Activating PACKAGE

gzip: initramfs.cpio.gz: decompression OK, trailing garbage ignored  
Following packages shall be activated:  
/flash/cat9k\_lite-webui.16.12.04.SPA.pkg  
/flash/cat9k\_lite-srdriver.16.12.04.SPA.pkg  
/flash/cat9k\_lite-rpboot.16.12.04.SPA.pkg  
/flash/cat9k\_lite-rpbase.16.12.04.SPA.pkg

This operation may require a reload of the system. **Do you want to proceed? [y/n]y**  
— Starting Activate —  
Performing Activate on all members  
Mar 11 08:53:53.512: %INSTALL-5-INSTALL\_AUTO\_ABORT\_TIMER\_PROGRESS: R0/0: rollback\_timer: Install auto abort timer will expire in 7200 seconds  
[1] Activate package(s) on switch 1  
— Starting list of software package changes —  
Old files list:  
Removed cat9k\_lite-rpbase.16.12.03a.SPA.pkg  
Removed cat9k\_lite-rpboot.16.12.03a.SPA.pkg  
Removed cat9k\_lite-srdriver.16.12.03a.SPA.pkg  
Removed cat9k\_lite-webui.16.12.03a.SPA.pkg  
New files list:  
Added cat9k\_lite-rpbase.16.12.04.SPA.pkg  
Added cat9k\_lite-rpboot.16.12.04.SPA.pkg  
Added cat9k\_lite-srdriver.16.12.04.SPA.pkg  
Added cat9k\_lite-webui.16.12.04.SPA.pkg  
Finished list of software package changes  
[1] Finished Activate on switch 1  
[2] Activate package(s) on switch 2  
— Starting list of software package changes —  
Old files list:  
Removed cat9k\_lite-rpbase.16.12.03a.SPA.pkg  
Removed cat9k\_lite-rpboot.16.12.03a.SPA.pkg  
Removed cat9k\_lite-srdriver.16.12.03a.SPA.pkg  
Removed cat9k\_lite-webui.16.12.03a.SPA.pkg  
New files list:  
Added cat9k\_lite-rpbase.16.12.04.SPA.pkg  
Added cat9k\_lite-rpboot.16.12.04.SPA.pkg  
Added cat9k\_lite-srdriver.16.12.04.SPA.pkg  
Added cat9k\_lite-webui.16.12.04.SPA.pkg  
Finished list of software package changes  
[2] Finished Activate on switch 2  
Checking status of Activate on [1 2]  
Activate: Passed on [1 2]  
Finished Activate

— Starting Commit —  
Performing Commit on all members  
[1] Commit package(s) on switch 1  
[1] Finished Commit on switch 1  
[2] Commit package(s) on switch 2  
[2] Finished Commit on switch 2  
Checking status of Commit on [1 2]  
Commit: Passed on [1 2]  
Finished Commit

Install will reload the system now!  
SUCCESS: install\_add\_activate\_commit Thu Mar 11 08:55:16 EST 2021  
Mar 11 08:55:17.946 %INSTALL-5-INSTALL\_COMPLETED\_INFO: R0/0: install\_engine: Completed install one-shot PACKAGE flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin  
9200L-24T-4G-E\_2#

---

<div class="post-metadata">

**Author:** ![ganeshrn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ganeshrn/32/1021_2.png) [@ganeshrn](https://forum.ansible.com/u/ganeshrn)\
**Post date:** [March 11, 2021, 3:31pm UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763/3 "2021-03-11T15:31:53Z")

</div>

You can use cli\_command module to handle multiple prompts on network device.  
Refer:

[https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/cli\_command\_module.html](https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/cli_command_module.html)

---

<div class="post-metadata">

**Author:** ![chr00ted](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chr00ted/32/2188_2.png) [@chr00ted](https://forum.ansible.com/u/chr00ted)\
**Post date:** [March 11, 2021, 4:25pm UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763/4 "2021-03-11T16:25:50Z")

</div>

Thanks Ganesh,

I’ll give that a try and let you know.

---

<div class="post-metadata">

**Author:** ![chr00ted](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chr00ted/32/2188_2.png) [@chr00ted](https://forum.ansible.com/u/chr00ted)\
**Post date:** [March 12, 2021, 1:57pm UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763/5 "2021-03-12T13:57:43Z")

</div>

I have tried using: ansible.netcommon.cli\_command

Here is the snippet of playbook that is failing:

- name: Copy IOS to all stack members and update  
ansible.netcommon.cli\_command:  
command: install add file flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin activate commit  
check\_all: true  
prompt:
- “This operation may require a reload of the system. Do you want to proceed”
- “Install will reload the system now”  
answer:
- y
- y

Since I tested initially I had some timeout issues, so prior to running, I ran:  
export ANSIBLE\_PERSISTENT\_TIMEOUT=2700

I still receive timeout failures:

The full traceback is:  
WARNING: The below traceback may _not_ be related to the actual failure.  
File “/tmp/ansible\_ansible.netcommon.cli\_command\_payload\_ApkceD/ansible\_ansible.netcommon.cli\_command\_payload.zip/ansible\_collections/ansible/netcommon/plugins/modules/cli\_command.py”, line 170,  
File “/tmp/ansible\_ansible.netcommon.cli\_command\_payload\_ApkceD/ansible\_ansible.netcommon.cli\_command\_payload.zip/ansible/module\_utils/connection.py”, line 185, in **rpc**  
raise ConnectionError(to\_text(msg, errors=‘surrogate\_then\_replace’), code=code)  
fatal: [10.82.2.125]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“answer”: [  
“y”,  
“y”  
],  
“check\_all”: true,  
“command”: “install add file flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin activate commit”,  
“newline”: true,  
“prompt”: [  
“This operation may require a reload of the system. Do you want to proceed”,  
“Install will reload the system now”  
],  
“sendonly”: false  
}  
},  
“msg”: “timeout value 30 seconds reached while trying to send command: install add file flash:cat9k\_lite\_iosxe.16.12.04.SPA.bin activate commit”  
}

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![chr00ted](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chr00ted/32/2188_2.png) [@chr00ted](https://forum.ansible.com/u/chr00ted)\
**Post date:** [March 12, 2021, 6:32pm UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763/6 "2021-03-12T18:32:37Z")

</div>

I resolved this by editing the ansible.cfg variable command\_timeout = 30 to command\_timeout = 2700 (accounting for the long operation of copying files across stack members and updating.

I’d rather not keep this variable at 2700. Is there a way I can temporarily set this variable in group\_var or elsewhere?

---

<div class="post-metadata">

**Author:** ![chr00ted](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chr00ted/32/2188_2.png) [@chr00ted](https://forum.ansible.com/u/chr00ted)\
**Post date:** [March 12, 2021, 8:10pm UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763/7 "2021-03-12T20:10:32Z")

</div>

I answered my own question 😉

I added command\_timeout = 2700 to group\_vars

Have a good weekend

---

<div class="post-metadata">

**Author:** ![ganeshrn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ganeshrn/32/1021_2.png) [@ganeshrn](https://forum.ansible.com/u/ganeshrn)\
**Post date:** [March 13, 2021, 2:01am UTC](https://forum.ansible.com/t/ansible-upgrade-cisco-switch-stack-firmware/34763/8 "2021-03-13T02:01:57Z")

</div>

If the high value of persistent command timeout is applicable for one task it can be set at task level. Refer  
[https://docs.ansible.com/ansible/devel/network/user\_guide/network\_debug\_troubleshooting.html#command-timeout](https://docs.ansible.com/ansible/devel/network/user_guide/network_debug_troubleshooting.html#command-timeout)
