0

Using Ansible 2.10.7 :

ansible 2.10.7
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/admin/.local/lib/python3.8/site-packages/ansible
  executable location = /home/admin/.local/bin/ansible
  python version = 3.8.7 (default, Jun 21 2021, 18:32:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

on a CentOS7 machine, I'm trying to using a custom collection andI'm getting the following error :

Exception: CollectionModuleUtilLocator can only locate below ansible_collections.(ns).(coll).plugins.module_utils, got ('ansible_collections', 'sdp', 'firewall_automation', 'plugins', 'modules', 'globals')
fatal: [localhost]: FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}

My collection is located in : /home/admin/.ansible/collections/ansible_collections/sdp/firewall_automation

and my ansible.cfg look like :

[defaults]
collections_paths = /home/admin/.ansible/collections/
inventory = /etc/ansible/hosts
host_key_checking = false

It looks like my collection is badly placed, but I use this collection on other machine without this error with the same config.

The full error traceback is :

Traceback (most recent call last):
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/executor/task_executor.py", line 158, in run
    res = self._execute()
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/executor/task_executor.py", line 663, in _execute
    result = self._handler.run(task_vars=variables)
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/plugins/action/normal.py", line 47, in run
    result = merge_hash(result, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/plugins/action/__init__.py", line 861, in _execute_module
    (module_style, shebang, module_data, module_path) = self._configure_module(module_name=module_name, module_args=module_args, task_vars=task_vars)
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/plugins/action/__init__.py", line 231, in _configure_module
    (module_data, module_style, module_shebang) = modify_module(module_name, module_path, module_args, self._templar,
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/executor/module_common.py", line 1299, in modify_module
    (b_module_data, module_style, shebang) = _find_module_utils(module_name, b_module_data, module_path, module_args, task_vars, templar, module_compression,
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/executor/module_common.py", line 1139, in _find_module_utils
    recursive_finder(module_name, remote_module_fqn, b_module_data, zf)
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/executor/module_common.py", line 917, in recursive_finder
    module_info = CollectionModuleUtilLocator(py_module_name, is_ambiguous=is_ambiguous, child_is_redirected=child_is_redirected)
  File "/home/admin/.local/lib/python3.8/site-packages/ansible/executor/module_common.py", line 807, in __init__
    raise Exception('CollectionModuleUtilLocator can only locate below ansible_collections.(ns).(coll).plugins.module_utils, got {0}'
Exception: CollectionModuleUtilLocator can only locate below ansible_collections.(ns).(coll).plugins.module_utils, got ('ansible_collections', 'sdp', 'firewall_automation', 'plugins', 'modules', 'globals')
fatal: [localhost]: FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}
NeitoFR
  • 716
  • 1
  • 11
  • 23
  • can you add output of `find ~/.ansible/collections/ansible_collections -name __init__.py` command ? – P.... Jun 21 '21 at 20:23
  • there is no output for this command – NeitoFR Jun 21 '21 at 21:11
  • how about `find ~/.ansible/collections/ansible_collections/sdp -name "*.py"` – P.... Jun 21 '21 at 21:12
  • There is many python files in the folder, like : ``` /home/admin/.ansible/collections/ansible_collections/sdp/firewall_automation/plugins/inventory/__init__.py /home/admin/.ansible/collections/ansible_collections/sdp/firewall_automation/plugins/inventory/firewall_inventory.py /home/admin/.ansible/collections/ansible_collections/sdp/firewall_automation/plugins/module_utils/sdp_utils.py /home/admin/.ansible/collections/ansible_collections/sdp/firewall_automation/plugins/modules/fw_json_check.py ``` Those are my custom made plugins – NeitoFR Jun 21 '21 at 21:17
  • check this `source code` https://github.com/ansible/ansible/blob/devel/lib/ansible/executor/module_common.py , here line 449 to 461. apparently your collection is not having `init` is causing path build to fail. – P.... Jun 21 '21 at 21:21
  • I don't understand why would it be necessary on this particular machine but not on the other two. I'm working on a WSL env (with ansible 2.9.15/python 3.6.8) and another centos7 machine (with ansible 2.9.15 and python 3.8.5) and those two can use the collection like a charm) – NeitoFR Jun 21 '21 at 21:33
  • I downgraded the ansible version from 2.10.7 to 2.9.15 to match the other two env but the error is the same – NeitoFR Jun 21 '21 at 21:34
  • you should use `find` command to compare the content of your collection path in the two machines. I do not know the reason, but there should be some difference in the contents. you can try `find /home/admin/.ansible/collections/ansible_collections/ -ls` – P.... Jun 21 '21 at 21:35
  • I'm trying to look but the output is not really digest, there bof the result of a git clone command. so for you the problem is becasue some directory isn't placed where it shoudl be ? – NeitoFR Jun 21 '21 at 21:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/234045/discussion-between-neitofr-and-p). – NeitoFR Jun 21 '21 at 21:52

0 Answers0