ansible-collections / ansible-collections/cloud.common

Turbo server doesn't use collection/role paths from `ansible.cfg` in the current directory.

Open
#158 0 comments 0 reactions 0 assignees View on GitHub
needs_verified
Dominant language
Python
Stars
19
Forks
28
PR merge metrics
No merged PRs in 30d

Description

##### SUMMARY
The server doesn't use the `ansible.cfg` in the current directory like ansible would do by default because current working directory is set to `/` on start.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
[turbo/server.py:84](https://github.com/ansible-collections/cloud.common/blob/main/plugins/module_utils/turbo/server.py#L84)

##### ANSIBLE VERSION

```paste below
ansible [core 2.15.9]
config file = /home/alabate/Projects/iac/ansible.cfg
configured module search path = ['/home/alabate/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/alabate/Projects/iac/.venv/lib/python3.11/site-packages/ansible
ansible collection location = /home/alabate/Projects/iac/.galaxy/collections:/home/alabate/Projects/iac
executable location = /home/alabate/Projects/iac/.venv/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/alabate/Projects/iac/.venv/bin/python)
jinja version = 3.1.3
libyaml = True
```

##### COLLECTION VERSION
```
# /home/alabate/Projects/iac/.galaxy/collections/ansible_collections
Collection Version
------------ -------
cloud.common 3.0.0
```

##### CONFIGURATION

```
COLLECTIONS_PATHS(/home/alabate/Projects/iac/ansible.cfg) = ['/home/alabate/Projects/iac/.galaxy/collections', '/home/alabate/Projects/iac>
CONFIG_FILE() = /home/alabate/Projects/iac/ansible.cfg
DEFAULT_FORKS(/home/alabate/Projects/iac/ansible.cfg) = 50
DEFAULT_HOST_LIST(/home/alabate/Projects/iac/ansible.cfg) = ['/home/alabate/Projects/iac/:']
DEFAULT_JINJA2_EXTENSIONS(/home/alabate/Projects/iac/ansible.cfg) = jinja2.ext.do
DEFAULT_ROLES_PATH(/home/alabate/Projects/iac/ansible.cfg) = ['/home/alabate/Projects/iac/.galaxy/roles']
DEFAULT_STDOUT_CALLBACK(/home/alabate/Projects/iac/ansible.cfg) = ansible.posix.debug
HOST_KEY_CHECKING(/home/alabate/Projects/iac/ansible.cfg) = False
INVENTORY_ENABLED(/home/alabate/Projects/iac/ansible.cfg) = ['sowi.awx.hybrid', 'host_list', 'script', 'auto', 'sowi.awx.yaml', 'ini', 'to>
PAGER(env: PAGER) = less
VARIABLE_PRECEDENCE(/home/alabate/Projects/iac/ansible.cfg) = ['all_plugins_inventory', 'all_plugins_play', 'all_inventory', 'groups_plugi>
```

##### OS / ENVIRONMENT
Ubuntu 22.04

##### STEPS TO REPRODUCE
Go give more context on our use case: we commit an `ansible.cfg` that set `roles_path` and `collections_path` at the root of the project. `ansible-playbook` will [automatically load it if you start it in this directory](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#the-configuration-file). This is how ansible find our local collections.

But the turbo server set [the current working directory to `/`](https://github.com/ansible-collections/cloud.common/blob/main/plugins/module_utils/turbo/server.py#L84) when it starts. So our `ansible.cfg` is never found and we get the following error when it tries to use it

```
No _run() found.
```
This error [come from here](https://github.com/ansible-collections/cloud.common/blob/main/plugins/module_utils/turbo/server.py#L253) when `plugin_loader.lookup_loader.get()` cannot find the collection, so it return None.

If I comment the line where the cwd is set to `/`, the turbo server finds the collection without issues

##### EXPECTED RESULTS
The turbo server should load the `ansible.cfg` of my current directory, or maybe at least extract collection/role path?

##### ACTUAL RESULTS
```paste below
Loading collection sowi.op from /home/alabate/Projects/iac/ansible_collections/sowi/op
Loading collection cloud.common from /home/alabate/Projects/iac/.galaxy/collections/ansible_collections/cloud/common
exception during Jinja2 execution: Traceback (most recent call last):
File "/home/alabate/Projects/iac/.venv/lib/python3.11/site-packages/ansible/template/__init__.py", line 879, in _lookup
ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alabate/Projects/iac/.galaxy/collections/ansible_collections/cloud/common/plugins/plugin_utils/turbo/lookup.py", line 57, in run_on_daemon
return self.execute(terms=terms, variables=variables, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alabate/Projects/iac/.galaxy/collections/ansible_collections/cloud/common/plugins/plugin_utils/turbo/lookup.py", line 91, in execute
raise EmbeddedModuleUnexpectedFailure(errors)
ansible_collections.cloud.common.plugins.module_utils.turbo.exceptions.EmbeddedModuleUnexpectedFailure: No _run() found
fatal: [localhost]: FAILED! => {}

MSG:

An unhandled exception occurred while running the lookup plugin 'vmware.vmware_rest.folder_moid'. Error was a , original message: No _run() found. No _run() found

```

Contributor guide

Open the contributing guide

Research direction

Start in plugins/module_utils/turbo/server.py at the current-working-directory change around line 84, then trace the plugin_loader.lookup_loader.get() failure around line 253. Reproduce the lookup with an ansible.cfg in the current directory and verify that its collection and role paths are honored, avoiding the resulting “No _run() found” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.