Open Akasurde opened 10 months ago
cc @ryandyf
@Akasurde Thank you for transferring this over. The reason why I had made the ticket in core was because the issue also occurred with the ansible.builtin.copy module, though to be fair, the behavior was slightly different but the issue at hand was the same.
Hey Netcommon Team, Sivel over that the core team found the cause of this bug. Attaching reply here, referencing: https://github.com/ansible/ansible/issues/82572#issuecomment-1906778882
Alright, with that information, I've been able to dig into this more and determine that the issue is indeed with the
net_put
action plugin fromansible.netcommon
.First, I'll copy one of the important sections from the original output:
ok: [CISCO_RTR_TEST] => { "changed": false, "destination": "flash:/c2951-universalk9-mz.SPA.155-3.M9.bin", "msg": "Warning: 'utf-8' codec can't decode byte 0xc8 in position 19: invalid continuation byte idempotency check failed. Check dest" }
That
msg
is the key here to tracing this further. When thatmsg
is displayed, it is because the call to_handle_existing_file
raised an exception.The issue is within
_handle_existing_file
, due to the fact that the remote file is downloaded to a uuid4 named temp file in the cwd, and then is opened in text mode, and not binary mode. Opening and reading in text mode results in aUnicodeDecodeError
that is not caught by the plugin, and thus never removes the temp file that was meant to be used for checksum comparison.There are probably a couple of changes that need to be made to
net_put
to operate more smoothly:
- Open the files with
rb
instead ofr
- Remove the call to
to_bytes
, as the contents are already bytes after (1)- Expand the
try/except
to justexcept Exception:
instead of only(IOError, OSError)
In any case, this information will be needed over at ansible-collections/ansible.netcommon#617 in order to get this resolved.
The silent transition to running
copy
locally would also need resolved in netcommon.
@KB-perByte Hey, is there any update to this? Thanks!
Summary
When transferring a new IOS file to a Cisco Router, an unexpected behavior occurs where a copy of the IOS file also gets created locally (in the project folder) as a random UUID name.
So not only is the bin file being copied to the router, it is also being copied to where I store my ansible project and where I am executing the playbooks from. The way I understand it, the copy module & net_put module are supposed to only copy the file to the remote destination. And what's also interesting, is that I have other playbooks that use the copy module and work perfectly fine/does not replicate this behavior.
Another interesting behavior I am noticing is, if I force the inventory file to use the wrong ssh password, the copy/net_put task reports 'changed'/'ok', placing the bin file in my project folder (but since the password is wrong, it does not get placed on the router). I know it's accessing the host designated in the playbook correctly because the task after the copy/net_put tries to run but cannot (since I forced the password wrong).
Issue Type
Bug Report
Component Name
net_put copy
Ansible Version
Configuration
OS / Environment
Steps to Reproduce
Playbook
Inventory
Extra Vars
('{"host_router_cisco":"CISCO_RTR_TEST","host_switch_cisco":null,"host_router_j":null,"host_switch_j":null,"ios_location":"/home/labtesting/Ansible/2951/c2951-universalk9-mz.SPA.155-3.M9","ios_filename":"c2951-universalk9-mz.SPA.155-3.M9.bin","ios_filesize":109728408}',)
Expected Results
I expected the playbook to not target the localhost aswell. Only the cisco router that the playbook calls for.
Actual Results
Code of Conduct