ansible-collections / ansible.netcommon

Ansible Network Collection for Common Code
GNU General Public License v3.0
144 stars 104 forks source link

Initializing SCP session of remote file for write failed with error [b'Socket error: Success'] #484

Closed arnaudtuihani closed 2 years ago

arnaudtuihani commented 2 years ago
SUMMARY

I'm trying to upgrade the IOS on my cisco switch with an ansible playbook.

When I try to launch this task :

- name: COPY IOS
  ansible.common.net_put:
    src: "~/GitLab/ansible-roles/cisco-upgrade-2960S/files/c2960s-universalk9-mz.152-2.E9.bin"
    dest: "flash:/c2960s-universalk9-mz.152-2.E9.bin"
    protocol: scp

It fails.

ISSUE TYPE
COMPONENT NAME

module ansible.netcommon (net_put)

ANSIBLE VERSION
ansible [core 2.12.2]
  config file = /home/at/GitLab/ansible-playbooks/cisco/ansible.cfg
  configured module search path = ['/home/at/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/at/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Apr  5 2022, 08:07:47) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10.0.1)]
  jinja version = 2.10.3
  libyaml = True
COLLECTION VERSION
at@srv-ansible cisco]$ ansible-galaxy collection list ansible.netcommon

# /usr/lib/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 2.5.1

# /home/at/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 4.1.0
[at@srv-ansible cisco]$ ansible-galaxy collection list cisco.ios

# /usr/lib/python3.8/site-packages/ansible_collections
Collection Version
---------- -------
cisco.ios  2.7.1

# /home/at/.ansible/collections/ansible_collections
Collection Version
---------- -------
cisco.ios  4.0.0
CONFIGURATION
DEFAULT_LOG_PATH(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = /home/at/ansible.log
DEFAULT_MANAGED_STR(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = Ansible managed /!\ do not edit
DEFAULT_REMOTE_USER(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = root
DEFAULT_ROLES_PATH(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = ['/home/at/GitLab/ansible-playbooks/cisco/roles', '/home/at>
DEFAULT_TIMEOUT(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = 90
DEFAULT_VAULT_PASSWORD_FILE(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = /home/at/.vault_pass.txt
DEPRECATION_WARNINGS(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = True
HOST_KEY_CHECKING(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = False
RETRY_FILES_ENABLED(/home/at/GitLab/ansible-playbooks/cisco/ansible.cfg) = False
OS / ENVIRONMENT

[at@srv-ansible cisco]$ cat /etc/os-release NAME="Oracle Linux Server" VERSION="8.6" ID="ol" ID_LIKE="fedora" VARIANT="Server" VARIANT_ID="server" VERSION_ID="8.6" PLATFORM_ID="platform:el8" PRETTY_NAME="Oracle Linux Server 8.6" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:oracle:linux:8:6:server" HOME_URL="https://linux.oracle.com/" BUG_REPORT_URL="https://bugzilla.oracle.com/"

ORACLE_BUGZILLA_PRODUCT="Oracle Linux 8" ORACLE_BUGZILLA_PRODUCT_VERSION=8.6 ORACLE_SUPPORT_PRODUCT="Oracle Linux" ORACLE_SUPPORT_PRODUCT_VERSION=8.6

STEPS TO REPRODUCE

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
On every website that i'v seen, this net_put module should work.

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
TASK [cisco-upgrade-2960S : COPY] *************************************************************************************************
task path: /home/at/GitLab/ansible-roles/cisco-upgrade-2960S/tasks/main.yml:15
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
<10.10.105.232> attempting to start connection
<10.10.105.232> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /usr/bin/ansible-connection
<10.10.105.232> found existing local domain socket, using it!
<10.10.105.232> updating play_context for connection
<10.10.105.232>
<10.10.105.232> local domain socket path is /home/at/.ansible/pc/a8a9396665
Getting network OS from inventory
fatal: [10.10.105.232]: FAILED! => {
    "changed": false,
    "destination": "flash:/c2960s-universalk9-mz.152-2.E9.bin",
    "msg": "Exception received: Error transferring file to flash:/c2960s-universalk9-mz.152-2.E9.bin: Initializing SCP session of remote file [flash:/c2960s-universalk9-mz.152-2.E9.bin] for write failed with error [b'Socket error: Success']"
}

PLAY RECAP ***********************************************************************************************************************************************************
10.10.105.232              : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
crytectobi commented 2 years ago

I'm running into the same issue since today

Task

        - name: Start Copy from Server
          net_put: 
            src: "/etc/ansible/c2960s-universalk9-mz.152-2.E9.bin"
            dest: "flash:/c2960s-universalk9-mz.152-2.E9.bin"
          vars:
              protocol: scp
              ansible_command_timeout: 3000

ANSIBLE VERSION

ansible [core 2.13.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/tblachetta/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/tblachetta/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/tblachetta/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.15 (main, Oct 12 2022, 19:15:11) [GCC 7.5.0]
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION

# /usr/local/lib/python3.9/dist-packages/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 3.1.3  

# /home/tblachetta/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 4.1.0  

OS / ENVIRONMENT

NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

ACTUAL RESULTS

TASK [Start Copy from Server] ****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
task path: /etc/ansible/tasks/cisco_ios_upgrade_new.yml:69
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
<10.129.255.100> attempting to start connection
<10.129.255.100> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /usr/local/bin/ansible-connection
<10.129.255.100> found existing local domain socket, using it!
<10.129.255.100> updating play_context for connection
<10.129.255.100> 
<10.129.255.100> local domain socket path is /home/tblachetta/.ansible/pc/f6db148676
redirecting (type: modules) ansible.builtin.net_put to ansible.netcommon.net_put
redirecting (type: action) ansible.builtin.net_put to ansible.netcommon.net_put
redirecting (type: action) ansible.builtin.net_put to ansible.netcommon.net_put
Getting network OS from inventory
fatal: [de-bre-ccb-e04-dot1xtest]: FAILED! => {
    "changed": false,
    "destination": "flash:/c2960x-universalk9-mz.152-7.E3.bin",
    "msg": "Exception received: Error transferring file to flash:/c2960x-universalk9-mz.152-7.E3.bin: Initializing SCP session of remote file [flash:/c2960x-universalk9-mz.152-7.E3.bin] for write failed with error [b'Socket error: No such file or directory']"
}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
de-bre-ccb-e04-dot1xtest   : ok=6    changed=0    unreachable=0    failed=1    skipped=1    rescued=0    ignored=0
crytectobi commented 2 years ago

Okay I fixed the issue for me. I uninstalled ansible-pylibssh. Now the net_put is working fine again. Don't know how this is related and why this started to be broken?!

@IzxxY can you check if this fixes the issue for you as well?

arnaudtuihani commented 2 years ago

Hello @crytectobi

I tried to uninstalled ansible-pylibssh and Installed paramiko 2.12. I'm getting this error now:

TASK [dinum.cisco-upgrade-2960S : test copy scp] ********************************************************************************************************************* fatal: [10.10.105.232]: FAILED! => {"changed": false, "destination": "flash:/c2960s-universalk9-mz.152-2.E9.bin", "msg": "Exception received: Failed to import the required Python library (scp) on srv-ansible.admin.nc's Python /usr/bin/python3.8. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}

arnaudtuihani commented 2 years ago

After installing scp

pip3.8 install --user scp

My task is now working !! Thank you @crytectobi

TASK [dinum.cisco-upgrade-2960S : test copy scp] ********************************************************************************************************************* changed: [10.10.105.232]