aruba / aoscx-ansible-collection

Ansible collections for AOS-CX switches 
47 stars 23 forks source link

ansible 2.10+ error: "unterminated character set at position 0" and "unable to decode json from response to exec_command" #10

Closed pixeldoc2000 closed 2 years ago

pixeldoc2000 commented 2 years ago

Playbook Example:

- hosts: aruba_cx
  collections:
    - arubanetworks.aoscx
  vars:
    ansible_connection: network_cli  # SSH
  tasks:
    - name: VLAN 3022 Name
      aoscx_command:
        commands:
          - 'configure'
          - 'vlan 3022'
          - 'name ADM-MGMT'
          - 'exit'
          - 'write memory'

inventory:

aruba_cx:
  hosts:
    rz02sa01sw01:
      ansible_host: rz02sa01sw01.example.com
    rz02sa01sw02:
      ansible_host: rz02sa01sw02.example.com
  vars:
    ansible_network_os: arubanetworks.aoscx.aoscx  # Don't change
    ansible_aoscx_validate_certs: False
    ansible_aoscx_use_proxy: False

With ansible 2.10.7 or 2.11.5 i get the error with this playbook: unterminated character set at position 0

The full traceback is:
  File "/tmp/ansible_aoscx_command_payload_fsmhikms/ansible_aoscx_command_payload.zip/ansible_collections/arubanetworks/aoscx/plugins/module_utils/aoscx.py", line 402, in run_commands
    return conn.run_commands(commands=commands, check_rc=check_rc)
  File "/tmp/ansible_aoscx_command_payload_fsmhikms/ansible_aoscx_command_payload.zip/ansible/module_utils/connection.py", line 195, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [rz02sa02sw01]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "commands": [
                "configure",
                "vlan 3022",
                "name ADM-MGMT",
                "exit",
                "write memory"
            ],
            "interval": 1,
            "match": "all",
            "output_file": null,
            "output_file_format": "json",
            "provider": null,
            "retries": 10,
            "wait_for": null
        }
    },
    "msg": "unterminated character set at position 0"
}

Error with other Playbook: Unable to decode JSON from response to exec_command('show running-config'). Received 'None'.

If i downgrade to ansible 2.9.26 everything runs fine:

$ pip uninstall ansible ansible-base ansible-core
$ pip install ansible==2.9.26

$ python3 -m pip list
Package            Version
------------------ ---------
ansible            2.9.26
ansible-pylibssh   0.2.0
...
paramiko           2.7.2
...
pyaoscx            2.0.1
pycparser          2.20

$ ansible --version
ansible 2.9.26
  config file = /home/user/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/ansible/lib/python3.9/site-packages/ansible
  executable location = /home/user/ansible/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]

Enviroment: Debian 11 with python 3.9 in virtualenv, fresh install with current packages.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

$ python3 -V
Python 3.9.2

$ python3 -m pip list
Package            Version
------------------ ---------
ansible            4.6.0
ansible-core       2.11.5
ansible-pylibssh   0.2.0
attrs              21.2.0
bcrypt             3.2.0
certifi            2021.5.30
cffi               1.14.6
charset-normalizer 2.0.6
cryptography       3.4.8
future             0.18.2
idna               3.2
Jinja2             3.0.1
jsonschema         4.0.0
jxmlease           1.0.3
lxml               4.6.3
MarkupSafe         2.0.1
ncclient           0.6.12
netaddr            0.8.0
packaging          21.0
paramiko           2.7.2
pip                20.3.4
pkg-resources      0.0.0
pyaoscx            2.0.1
pycparser          2.20
PyNaCl             1.4.0
pyparsing          2.4.7
pyrsistent         0.18.0
PyYAML             5.4.1
requests           2.26.0
resolvelib         0.5.4
setuptools         44.1.1
six                1.16.0
textfsm            1.1.2
ttp                0.8.0
urllib3            1.26.7
wheel              0.34.2
xmltodict          0.12.0

$ ansible --version
ansible [core 2.11.5]
  config file = /home/user/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/ansible/lib/python3.9/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/ansible/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.0.1
  libyaml = True

$ ansible-galaxy collection list

# /home/user/.ansible/collections/ansible_collections
Collection               Version
------------------------ -------
ansible.netcommon        2.4.0
ansible.utils            2.4.1
arubanetworks.aos_switch 1.4.0
arubanetworks.aoscx      3.0.1

# /home/user/ansible/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
ansible.netcommon             2.4.0
ansible.posix                 1.3.0
ansible.utils                 2.4.0
ansible.windows               1.7.2
...
tchiapuziowong commented 2 years ago

Hi @pixeldoc2000 ! We've been trying to get to the bottom of this issue as well - are you able to downgrade your netcommon collection to version 1.4.1 and see if the issue persists? ansible-galaxy collection install ansible.netcommon:1.4.1 -f

tchiapuziowong commented 2 years ago

We've opened an issue with Ansible's netcommon collection here: https://github.com/ansible-collections/ansible.netcommon/issues/301

tchiapuziowong commented 2 years ago

Also please make sure you've set

# uncomment this to disable SSH key host checking
host_key_checking = False

in your ansible.cfg file - to see which one you're using execute ansible --version

pixeldoc2000 commented 2 years ago
# uncomment this to disable SSH key host checking
host_key_checking = False

host_key_checking is disabled.

ansible.netcommon:1.4.1 does not support Ansible 2.11.5

TASK [Gathering Facts] ********************************************************************************************************************************************************************
[WARNING]: Collection ansible.netcommon does not support Ansible version 2.11.5
[WARNING]: Collection ansible.netcommon does not support Ansible version 2.11.5 
tchiapuziowong commented 2 years ago

@pixeldoc2000 the current workaround is to downgrade to ansible.netcommon==1.5.0 - we've opened up an issue with the Ansible collection and are pushing to get this resolved - thank you for your patience and understanding!

tchiapuziowong commented 2 years ago

I'm happy to announce a fix for this issue has been published and you can now pull the latest version of our Collection to verify: ansible-galaxy collection install arubanetworks.aoscx -f

Also ensure you're working with the most updated version of the ansible.netcommon library as well: ansible-galaxy collection install ansible.netcommon -f