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

Ansible 6 support #933

Merged
merged 6 commits into from
Jul 24, 2022
Merged

Ansible 6 support #933

merged 6 commits into from
Jul 24, 2022

Conversation

moreati
Copy link
Member

@moreati moreati commented Jun 2, 2022

No description provided.

@extmind
Copy link
Contributor

extmind commented Jun 12, 2022

I've tried this branch with Ansible 2.13 and Python 3.10. Its not clear to me if the error is the same as in CI, but here are my findings. While execution only stops later, this is the first traceback that I get:

[mux  212055] 17:05:06.914298 D mitogen: While importing 'ansible.module_utils.basic'
Traceback (most recent call last):
  File ".../mitogen/mitogen/master.py", line 1134, in _send_module_and_related
    tup = self._build_tuple(fullname)
  File ".../mitogen/mitogen/master.py", line 1087, in _build_tuple
    for name in self._finder.find_related(fullname)
  File ".../mitogen/mitogen/master.py", line 959, in find_related
    names = self.find_related_imports(name)
  File ".../mitogen/mitogen/master.py", line 933, in find_related_imports
    set(
  File ".../mitogen/mitogen/master.py", line 937, in <genexpr>
    and not is_stdlib_name(name)
  File ".../mitogen/mitogen/master.py", line 140, in is_stdlib_name
    modpath = os.path.abspath(getattr(module, '__file__', ''))
  File "/usr/lib/python3.10/posixpath.py", line 378, in abspath
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

This is caused by calling is_stdlib_name with jaraco which has its __file__ attribute set to None (as is explicitly allowed in Python's reference). jaraco is installed on my system as a dependency for setuptools.
This can be fixed by modpath = os.path.abspath(getattr(module, '__file__', '') or '') which would then let the function correctly return False, but this may not be adequate in a future situation. Another possibility may be to use a module's __path__ instead of __file__ which would be set in jaraco's case, but may also be empty according to the reference.
I think the best solution would be to replace this machinery altogether by importlib.sys.stdlib_module_names, but I don't know if this is available for all versions that mitogen tries to support. However, it probably should be the preferred variant if available.

moreati added 6 commits July 24, 2022 10:14
e.g. in Ansible 6, ansible-core 2.13

```
[mux  2717] 23:39:11.342416 D mitogen: PkgutilMethod(): _AnsibleCollectionLoader(path=None).get_file_name('ansible.plugins') failed: ValueError('_AnsibleCollectionLoader(path=None) cannot find files for ansible.plugins, only ansible_collections.ansible.builtin.plugins')
```
…precendence

Until Ansible 2.9 it looks like ansible_become_password had higher priority.
From Ansible 2.10 ansible_become_pass has higher priority [1]. Mitogen was not
respecting this.

I may need to rework this further, instatiating the become plugin may have
slowed down execution.

[1] Based on testing with

```
[ubuntus]
become-pass-pass ansible_become_pass=1234
become-pass-password ansible_become_password=1234
become-pass-both ansible_become_password=wrong ansible_become_pass=1234

[ubuntus:vars]
ansible_host=ubuntu2004.local
ansible_user=ubuntu
```
```
- hosts: ubuntus
  gather_facts: false
  become: true
  tasks:
    - ping:
```
@moreati moreati marked this pull request as ready for review July 24, 2022 10:31
@moreati moreati merged commit 8cda5f5 into mitogen-hq:master Jul 24, 2022
@moreati moreati deleted the ansible6 branch July 24, 2022 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants