aruba / aoscx-ansible-collection

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

Error: 'Connection' object has no attribute 'nonetype' #69

Closed smirlach closed 1 year ago

smirlach commented 1 year ago

Hello,

i'm trying to gather the software version from an Aruba OS-CX device with Ansible and get the error "Unexpected failure during module execution: 'Connection' object has no attribute 'nonetype'".

My Ansible setup:

❯ ansible --version
ansible [core 2.14.2]
  config file = /home/<myuser>/repos/test/ansible.cfg
  configured module search path = ['/home/<myuser>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible
  ansible collection location = /home/<myuser>/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/<myuser>/.pyenv/versions/3.9.15/bin/ansible
  python version = 3.9.15 (main, Nov 16 2022, 14:25:35) [GCC 9.4.0] (/home/<myuser>/.pyenv/versions/3.9.15/bin/python3)
  jinja version = 3.1.2
  libyaml = True

The version of the Ansible collection:

❯ ansible-galaxy collection list arubanetworks.aoscx

# /home/<myuser>/.ansible/collections/ansible_collections
Collection          Version
------------------- -------
arubanetworks.aoscx 4.0.3

The Ansible inventory I'm using:

all:
  children:
    ungrouped:
      hosts:
        myhost:
          ansible_acx_no_proxy: true
          ansible_aoscx_use_proxy: false
          ansible_aoscx_validate_certs: false
          ansible_connection: arubanetworks.aoscx.aoscx
          ansible_host: myhost.test
          ansible_network_os: arubanetworks.aoscx.aoscx
          ansible_password: <password>
          ansible_user: <user>

My Ansible playbook:

---
- hosts: all
  gather_facts: False
  collections:
    - arubanetworks.aoscx
  vars:
    ansible_python_interpreter: /usr/bin/python3
  tasks:

  - name: Gather facts
    aoscx_facts:
      gather_subset: software_version
    register: aruba_facts

  - name: debug
    debug:
      msg: 
        - "{{ aruba_facts }}"

The full verbose (-vvv) error output:

❯ ansible-playbook -i ansibletest/hosts_aruba.yaml ansibletest/play.yml --vault-password-file=/tmp/unlock -vvv
ansible-playbook [core 2.14.2]
  config file = /home/<myuser>/repos/test/ansible.cfg
  configured module search path = ['/home/<myuser>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible
  ansible collection location = /home/<myuser>/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/<myuser>/.pyenv/versions/3.9.15/bin/ansible-playbook
  python version = 3.9.15 (main, Nov 16 2022, 14:25:35) [GCC 9.4.0] (/home/<myuser>/.pyenv/versions/3.9.15/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /home/<myuser>/repos/test/ansible.cfg as config file
host_list declined parsing /home/<myuser>/repos/test/ansibletest/hosts_aruba.yaml as it did not pass its verify_file() method
script declined parsing /home/<myuser>/repos/test/ansibletest/hosts_aruba.yaml as it did not pass its verify_file() method
Parsed /home/<myuser>/repos/test/ansibletest/hosts_aruba.yaml inventory source with yaml plugin
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: play.yml *************************************************************************************************************************************************************
1 plays in ansibletest/play.yml

PLAY [all] *********************************************************************************************************************************************************************

TASK [Gather facts] ************************************************************************************************************************************************************
task path: /home/<myuser>/repos/test/ansibletest/play.yml:8
The full traceback is:
Traceback (most recent call last):
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/plugins/connection/__init__.py", line 293, in __getattr__
    return self.__dict__[name]
KeyError: '_nonetype'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 1001, in _set_plugin_options
    plugin = getattr(self._connection, '_%s' % plugin_type)
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/plugins/connection/__init__.py", line 301, in __getattr__
    raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
AttributeError: 'Connection' object has no attribute '_nonetype'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/plugins/connection/__init__.py", line 293, in __getattr__
    return self.__dict__[name]
KeyError: 'nonetype'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 158, in run
    res = self._execute()
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 556, in _execute
    plugin_vars = self._set_connection_options(cvars, templar)
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 1083, in _set_connection_options
    varnames.extend(self._set_plugin_options(plugin_type, variables, templar, task_keys))
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 1004, in _set_plugin_options
    plugin = getattr(self._connection, plugin_type)
  File "/home/<myuser>/.pyenv/versions/3.9.15/lib/python3.9/site-packages/ansible/plugins/connection/__init__.py", line 301, in __getattr__
    raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
AttributeError: 'Connection' object has no attribute 'nonetype'
fatal: [myhost]: FAILED! => {
    "msg": "Unexpected failure during module execution: 'Connection' object has no attribute 'nonetype'",
    "stdout": ""
}

One the one hand this seems to be an issue with Ansible itself https://github.com/ansible/ansible/issues/79371 with a fix already proposed but not implemented. On the other hand the issue also states that it is a good idea to set the _sub_plugin value for connection plugins.

So is the issue with my Ansible setup? Or is that _sub_plugin not implemented for this collection?

tchiapuziowong commented 1 year ago

Hi @smirlach - We can look into the _sub_plugin you referenced, in the meantime could you also try removing your declaration of ansible_python_interpreter: /usr/bin/python3 and updating your collection version? Since you're using a venv AND it's already python3 you should need that variable set, please let us know if the issue persists. in the meantime I'll work with development on recreating the issue

smirlach commented 1 year ago

Hi @tchiapuziowong - thanks for the hint. It's working now :+1: I tried installing the newest collection version before but unfortunately i had to overwrite it with --force now it installed the current version.

tchiapuziowong commented 1 year ago

Great to hear!