# Ansible ios\_command: copy tftp: flash: keeps sending IOS file data until timeout

**URL:** <https://forum.ansible.com/t/ansible-ios-command-copy-tftp-flash-keeps-sending-ios-file-data-until-timeout/30579>\
**Category:** Ansible Project\
**Created:** [June 16, 2019, 3:02pm UTC](https://forum.ansible.com/t/ansible-ios-command-copy-tftp-flash-keeps-sending-ios-file-data-until-timeout/30579 "2019-06-16T15:02:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frankie\_Soto](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@Frankie\_Soto](https://forum.ansible.com/u/Frankie_Soto)\
**Post date:** [June 16, 2019, 3:02pm UTC](https://forum.ansible.com/t/ansible-ios-command-copy-tftp-flash-keeps-sending-ios-file-data-until-timeout/30579/1 "2019-06-16T15:02:24Z")

</div>

Hi!

I am trying to automate the process of upgrading IOS on Cisco devices.

Everything seems to be working fine until the process of copying the file begins.

The issue I am encountering is that ansible keeps sending data (I assume it keeps sending the same file a couple of times in a stream) to the IOS device.

I noticed this issue when I logged in to one of the switches to which I am trying to upgrade and saw how the file keeps growing and growing, to up to four times its size (i.e. filesize is ~ 21k but it was growing already on th 80k+).

Process ends when the “timeout” time is reached. Subsequently, the file gets deleted from the switch, as the switches interprets that the file transfer was interrupted.

Here is y core. Any help will be much appreciated:

---

<div class="post-metadata">

**Author:** ![Mysimpia](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@Mysimpia](https://forum.ansible.com/u/Mysimpia)\
**Post date:** [January 14, 2020, 1:49pm UTC](https://forum.ansible.com/t/ansible-ios-command-copy-tftp-flash-keeps-sending-ios-file-data-until-timeout/30579/2 "2020-01-14T13:49:43Z")

</div>

Ansible version : 2.9  
Python version : 3.7.5

I also tried many times with sftp or scp with ios\_command module but no luck. Instead, as shown below, net\_put successfully copied the file over to the Cisco switch. The ansible\_ssh\_user and ansible\_ssh\_pass needs to be set in inventory file.

One issue I’m facing with the net\_put module is that next task using ios\_command after the copying fails to be executed. It gave error message “ConnectionError(to\_text(msg, errors=‘surrogate\_then\_replace’), code=code)”.

- name: Upgrade NM switch Firmware

hosts: nm\_switch  
connection: network\_cli  
remote\_user: cisco

- name: Copy over ios image  
net\_put:  
src: “{{ nm\_sw\_image\_file }}” # Need ansible\_ssh\_user and ansible\_ssh\_pass set up.  
vars:  
ansible\_command\_timeout: 3600 # default time out is 30 sec. Image copy takes about 30 min

---

<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:** [January 14, 2020, 4:14pm UTC](https://forum.ansible.com/t/ansible-ios-command-copy-tftp-flash-keeps-sending-ios-file-data-until-timeout/30579/3 "2020-01-14T16:14:59Z")

</div>

I had the same issue, I ended up using scp:

- name: COPY OVER IOS IMAGE  
command: “firmwarename.bin {{inventory\_hostname}}:flash:/firmwarename.bin”

I ran a separate playbook 1st to enable scp on the switches.

---

<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:** [January 14, 2020, 4:18pm UTC](https://forum.ansible.com/t/ansible-ios-command-copy-tftp-flash-keeps-sending-ios-file-data-until-timeout/30579/4 "2020-01-14T16:18:19Z")

</div>

Below is the playbook to enable scp on switches/routers:

tasks:

- name: IOS CONFIG 1a  
ios\_config:  
lines:
- ip scp server enable
