ansible-collections / ansible.netcommon

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

ssh_type libssh error Negative size passed to PyBytes_FromStringAndSize #444

Open epicanthal opened 2 years ago

epicanthal commented 2 years ago
SUMMARY

I am toying with the libssh connection method. I've learned of it via the Ansible 6.0.0 release notes for ansible.netcommon. When I switch to ssh_type=libssh or ssh_type=auto the error Negative size passed to PyBytes_FromStringAndSize is produced. The same playbook continues to work as expected when switching to ssh_type=paramiko

ISSUE TYPE
COMPONENT NAME

network_cli libssh

ANSIBLE VERSION
# ansible --version
ansible [core 2.13.1]
  config file = /project/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.2 (default, Mar 31 2021, 12:21:33) [GCC 8.3.0]
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# ansible-galaxy collection list ansible.netcommon

# /usr/local/lib/python3.9/site-packages/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 3.0.1  
CONFIGURATION
# ansible-config dump --only-changed
DEFAULT_ROLES_PATH(/project/ansible.cfg) = ['/project/roles']
HOST_KEY_CHECKING(/project/ansible.cfg) = False
INTERPRETER_PYTHON(/project/ansible.cfg) = /usr/local/bin/python
PARAMIKO_HOST_KEY_AUTO_ADD(/project/ansible.cfg) = True
PERSISTENT_COMMAND_TIMEOUT(/project/ansible.cfg) = 30
PERSISTENT_CONNECT_TIMEOUT(/project/ansible.cfg) = 30
OS / ENVIRONMENT

Docker:

FROM python:3.9.2-slim-buster

Target Device:

Hardware: Cisco WS-C3850-12X48U IOS Version: 16.9.5

PIP List:

Package            Version
------------------ ---------
ansible            6.0.0
ansible-core       2.13.1
ansible-pylibssh   0.4.0
bcrypt             3.2.2
certifi            2022.6.15
cffi               1.15.0
charset-normalizer 2.0.12
cryptography       37.0.2
idna               3.3
ijson              2.6.1
Jinja2             3.1.2
jmespath           1.0.1
MarkupSafe         2.1.1
netaddr            0.8.0
oauthlib           3.2.0
packaging          21.3
paramiko           2.11.0
pip                21.0.1
pycparser          2.21
PyNaCl             1.5.0
pyparsing          3.0.9
pysnow             0.7.17
python-magic       0.4.27
pytz               2019.3
PyYAML             6.0
requests           2.28.0
requests-oauthlib  1.3.1
resolvelib         0.8.1
setuptools         54.2.0
six                1.16.0
urllib3            1.26.9
wheel              0.36.2
WARNING: You are using pip version 21.0.1; however, version 22.1.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
STEPS TO REPRODUCE

Run: $ ansible-playbook -i inventory.ini ios_cli_test_connectivity.yml -l ios -v

- name: Cisco IOS Test Connectivity
  hosts: ios
  vars_prompt:
    - name: "ios_cli_username"
      prompt: "\nEnter CLI IOS username"
      private: no
    - name: "ios_cli_password"
      prompt: "\nEnter CLI password"
      private: yes
  gather_facts: no
  order: sorted

  vars:
    ansible_connection: ansible.netcommon.network_cli
    ansible_network_os: cisco.ios.ios
    ansible_user: "{{ ios_cli_username }}"
    ansible_password: "{{ ios_cli_password }}"

  tasks:
    - name: run 'show version'
      cisco.ios.ios_command:
        commands:
          - show version
EXPECTED RESULTS

I expect the contents of the show version ios command to be output (with -v) and successful completion of play. As mentioned above, I do receive the expected result if ssh_type=paramiko

ACTUAL RESULTS
ansible-playbook [core 2.13.1]
  config file = /project/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.9.2 (default, Mar 31 2021, 12:21:33) [GCC 8.3.0]
  jinja version = 3.1.2
  libyaml = True
Using /project/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /project/inventory.ini as it did not pass its verify_file() method
script declined parsing /project/inventory.ini as it did not pass its verify_file() method
auto declined parsing /project/inventory.ini as it did not pass its verify_file() method
yaml declined parsing /project/inventory.ini as it did not pass its verify_file() method
Set default localhost to localhost
Parsed /project/inventory.ini inventory source with ini plugin
Loading collection cisco.ios from /usr/local/lib/python3.9/site-packages/ansible_collections/cisco/ios
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: ios_cli_test_connectivity.yml ****************************************************************************************
Positional arguments: ios_cli_test_connectivity.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/project/inventory.ini',)
subset: ios
forks: 5
1 plays in ios_cli_test_connectivity.yml

Enter CLI IOS username: my_username

Enter CLI password: 

PLAY [Cisco IOS Test Connectivity] *********************************************************************************************
META: ran handlers

TASK [run 'show version'] ******************************************************************************************************
task path: /project/ios_cli_test_connectivity.yml:44
Loading collection ansible.netcommon from /usr/local/lib/python3.9/site-packages/ansible_collections/ansible/netcommon
<my_switch.my_company.com> attempting to start connection
<my_switch.my_company.com> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /usr/local/bin/ansible-connection
<my_switch.my_company.com> local domain socket does not exist, starting it
<my_switch.my_company.com> control socket path is /root/.ansible/pc/1334c8a7f0
<my_switch.my_company.com> Loading collection ansible.netcommon from /usr/local/lib/python3.9/site-packages/ansible_collections/ansible/netcommon
<my_switch.my_company.com> Loading collection cisco.ios from /usr/local/lib/python3.9/site-packages/ansible_collections/cisco/ios
<my_switch.my_company.com> local domain socket listeners started successfully
<my_switch.my_company.com> loaded cliconf plugin ansible_collections.cisco.ios.plugins.cliconf.ios from path /usr/local/lib/python3.9/site-packages/ansible_collections/cisco/ios/plugins/cliconf/ios.py for network_os cisco.ios.ios
<my_switch.my_company.com> ssh type is set to auto
<my_switch.my_company.com> autodetecting ssh_type
<my_switch.my_company.com> ssh type is now set to libssh
<my_switch.my_company.com> 
<my_switch.my_company.com> local domain socket path is /root/.ansible/pc/1334c8a7f0
<my_switch.my_company.com> Using network group action cisco.ios.ios for cisco.ios.ios_command
<my_switch.my_company.com> ANSIBLE_NETWORK_IMPORT_MODULES: enabled
<my_switch.my_company.com> ANSIBLE_NETWORK_IMPORT_MODULES: found cisco.ios.ios_command  at /usr/local/lib/python3.9/site-packages/ansible_collections/cisco/ios/plugins/modules/ios_command.py
<my_switch.my_company.com> ANSIBLE_NETWORK_IMPORT_MODULES: running cisco.ios.ios_command
<my_switch.my_company.com> ANSIBLE_NETWORK_IMPORT_MODULES: complete
The full traceback is:
  File "/usr/local/lib/python3.9/site-packages/ansible_collections/cisco/ios/plugins/module_utils/network/ios/ios.py", line 141, in run_commands
    return connection.run_commands(commands=commands, check_rc=check_rc)
  File "/usr/local/lib/python3.9/site-packages/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [my_switch.my_company.com]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "commands": [
                "show version",
                "exit"
            ],
            "interval": 1,
            "match": "all",
            "provider": null,
            "retries": 10,
            "wait_for": null
        }
    },
    "msg": "Negative size passed to PyBytes_FromStringAndSize"
}

PLAY RECAP *********************************************************************************************************************
my_switch.my_company.com : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
newtonwj commented 2 years ago

I also have this issue using the newer libssh method instead of paramiko. It occurs when I'm pulling facts using the nxos.nxos_facts module. Interestingly enough, it works fine the 1st time I run it in a playbook, but after the device reboots - nxos_facts fails the second time it runs when trying to refresh device facts for an assertion before moving forward. I'm running same Ansible version as you.

Here is a snippet of my code. #########################################################################

Here is my error: ###################################################################################### 90 p=79700 u=newtonw-sa@medres.strpweb.org n=ansible | TASK [Wait 5 minutes then start verifying if switch is up] ***** 2022-08-05 00:16:01,354 p=79700 u=newtonw-sa@medres.strpweb.org n=ansible | ok: [mvp-core-sw01] 2022-08-05 00:16:01,368 p=79700 u=newtonw-sa@medres.strpweb.org n=ansible | TASK [Refresh device information] ** 2022-08-05 00:16:02,644 p=79700 u=newtonw-sa@medres.strpweb.org n=ansible | fatal: [mvp-core-sw01]: FAILED! => changed=false msg: Negative size passed to PyBytes_FromStringAndSize #######################################################################################

satperm commented 1 year ago

Any updates? i have same issue with routeros.command module with libssh and paramiko transport