Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External connection plugins that do not set _sub_plugin trigger errors #79371

Closed
1 task done
jbemmel opened this issue Nov 13, 2022 · 1 comment · Fixed by #79372
Closed
1 task done

External connection plugins that do not set _sub_plugin trigger errors #79371

jbemmel opened this issue Nov 13, 2022 · 1 comment · Fixed by #79372
Labels
affects_2.13 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. networking Network category P3 Priority 3 - Approved, No Time Limitation test This PR relates to tests. traceback This issue/PR includes a traceback.

Comments

@jbemmel
Copy link
Contributor

jbemmel commented Nov 13, 2022

Summary

At https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/__init__.py#L282

self._sub_plugin = {}

Then at https://github.com/ansible/ansible/blob/devel/lib/ansible/executor/task_executor.py#L1081:

sub = getattr(self._connection, '_sub_plugin', None)
        if sub is not None and sub.get('type') != 'external':
            plugin_type = get_plugin_class(sub.get("obj"))
            varnames.extend(self._set_plugin_options(plugin_type, variables, templar, task_keys))

The built-in connection plugins all set _sub_plugin to some sane value, but older external plugins do not

Suggested fix: check for '{}' in addition to 'None'

sub = getattr(self._connection, '_sub_plugin', None)
        if sub and sub.get('type') != 'external':

Issue Type

Bug Report

Component Name

executor

Ansible Version

$ ansible --version
ansible [core 2.13.6]

  config file = /home/jeroen/srlinux/openbgpd-lab/ansible.cfg

  configured module search path = ['/home/jeroen/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible

  ansible collection location = /home/jeroen/.ansible/collections:/usr/share/ansible/collections

  executable location = /usr/local/bin/ansible

  python version = 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0]

  jinja version = 3.1.2

  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
DEFAULT_FILTER_PLUGIN_PATH(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = ['/home/jeroen/srlinux/openbgpd-lab/filter_plugins']

DEFAULT_FORKS(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = 10

DEFAULT_GATHERING(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = explicit

DEFAULT_HOST_LIST(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = ['/home/jeroen/srlinux/openbgpd-lab/hosts.yml']

DEFAULT_MANAGED_STR(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = # Ansible Managed File

DEFAULT_ROLES_PATH(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = ['/home/jeroen/srlinux/openbgpd-lab/roles']

DEFAULT_STDOUT_CALLBACK(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = yaml

DEPRECATION_WARNINGS(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = False

HOST_KEY_CHECKING(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = False

INTERPRETER_PYTHON(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = auto_silent

PARAMIKO_HOST_KEY_AUTO_ADD(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = False

PERSISTENT_COMMAND_TIMEOUT(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = 60

RETRY_FILES_ENABLED(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = False



CONNECTION:

==========



paramiko_ssh:

____________

host_key_auto_add(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = False

host_key_checking(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = False



ssh:

___

host_key_checking(/home/jeroen/srlinux/openbgpd-lab/ansible.cfg) = False

OS / Environment

Ubuntu 22.04.1 LTS (jammy) VM running Linux 5.15.0-52-generic

Steps to Reproduce

Use external connection plugin like https://github.com/nokia/ansible-networking-collections/tree/master/grpc

Expected Results

Playbook runs to completion

Actual Results

JvB: _connection type=<class 'ansible_collections.nokia.grpc.plugins.connection.gnmi.Connection'>

The full traceback is:

Traceback (most recent call last):

  File "/usr/local/lib/python3.10/dist-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 "/usr/local/lib/python3.10/dist-packages/ansible/executor/task_executor.py", line 1009, in _set_plugin_options

    plugin = getattr(self._connection, '_%s' % plugin_type)

  File "/usr/local/lib/python3.10/dist-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 "/usr/local/lib/python3.10/dist-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 "/usr/local/lib/python3.10/dist-packages/ansible/executor/task_executor.py", line 158, in run

    res = self._execute()

  File "/usr/local/lib/python3.10/dist-packages/ansible/executor/task_executor.py", line 574, in _execute

    plugin_vars = self._set_connection_options(cvars, templar)

  File "/usr/local/lib/python3.10/dist-packages/ansible/executor/task_executor.py", line 1092, in _set_connection_options

    varnames.extend(self._set_plugin_options(plugin_type, variables, templar, task_keys))

  File "/usr/local/lib/python3.10/dist-packages/ansible/executor/task_executor.py", line 1012, in _set_plugin_options

    plugin = getattr(self._connection, plugin_type)

  File "/usr/local/lib/python3.10/dist-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: [srlinux]: FAILED! => 

  msg: Unexpected failure during module execution.

  stdout: ''

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Nov 13, 2022

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.13 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. needs_triage Needs a first human triage before being processed. test This PR relates to tests. traceback This issue/PR includes a traceback. labels Nov 13, 2022
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 15, 2022
@sivel sivel added the networking Network category label Nov 15, 2022
@nitzmahone nitzmahone added the P3 Priority 3 - Approved, No Time Limitation label Aug 16, 2023
jbemmel added a commit to jbemmel/ansible that referenced this issue Sep 26, 2023
bcoca pushed a commit that referenced this issue Jan 3, 2024
…#79372)

fixes #79371

* Check for sub=={} too
* Add a test case for older plugins that do not define '_sub_plugin'
* Add test for legacy plugins
@ansible ansible locked and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.13 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. networking Network category P3 Priority 3 - Approved, No Time Limitation test This PR relates to tests. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants