ansibleguy/collection_opnsense

ValueError: ansible_collections.ansibleguy.opnsense.__spec__ is None

ansibleguy opened this issue · 6 comments

Discussed in #15

Originally posted by riffy99 May 9, 2023
Hi, I've spent a good while trying to get up and running but have hit an issue I can't see the cause of. I'm sure I have the correct install, and I've tried on a number of machines with the same result.

My playbook looks like this:

#
---
- hosts: 4D_FW
  connection: local
  gather_facts: no
  tasks:
    - name: Example
      ansibleguy.opnsense.alias:
        firewall: "{{ ansible_host }}"
        api_credential_file: 'api.key'
        ssl_verify: false
    - name: Example_test
      ansibleguy.opnsense.alias:
        name: 'ANSIBLE_TEST1'
        type: 'host'
        content: ['1.1.1.1']

But I'm getting this error:

ASK [Example] *********************************************************************************************************************************************************************
task path: /Users/richard.fry/4d_fw.yml:9
<10.40.0.11> ESTABLISH LOCAL CONNECTION FOR USER: richard.fry
<10.40.0.11> EXEC /bin/sh -c 'echo ~richard.fry && sleep 0'
<10.40.0.11> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/richard.fry/.ansible/tmp `"&& mkdir "` echo /Users/richard.fry/.ansible/tmp/ansible-tmp-1683642816.998871-66703-99538016419058 `" && echo ansible-tmp-1683642816.998871-66703-99538016419058="` echo /Users/richard.fry/.ansible/tmp/ansible-tmp-1683642816.998871-66703-99538016419058 `" ) && sleep 0'
<10.40.0.11> EXEC /bin/sh -c 'rm -f -r /Users/richard.fry/.ansible/tmp/ansible-tmp-1683642816.998871-66703-99538016419058/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/task_executor.py", line 158, in run
    res = self._execute()
  File "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/task_executor.py", line 663, in _execute
    result = self._handler.run(task_vars=variables)
  File "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/module_common.py", line 812, in __init__
    self._locate()
  File "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/module_common.py", line 706, in _locate
    if self._find_module(candidate_name_parts):
  File "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/module_common.py", line 832, in _find_module
    src = pkgutil.get_data(collection_pkg_name, to_native(os.path.join(resource_base_path, '__init__.py')))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pkgutil.py", line 619, in get_data
    spec = importlib.util.find_spec(package)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/util.py", line 114, in find_spec
    raise ValueError('{}.__spec__ is None'.format(name))
ValueError: ansible_collections.ansibleguy.opnsense.__spec__ is None
fatal: [10.40.0.11]: FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}

PLAY RECAP *************************************************************************************************************************************************************************
10.40.0.11                 : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Any pointers would be greatly appreciated.
Thanks, Richard

@riffy99 Please provide your Python3, Ansible and collection versions:

# python version
python3 --version

# collection version
ansible-galaxy collection list | grep opnsense

# ansible version
python3 -m pip list | grep ansible
# or
apt policy ansible

- AnsibleGuy

M601153-2:~ richard.fry$ python3 --version
Python 3.8.7

M601153-2:~ richard.fry$ ansible-galaxy collection list | grep opnsense
ansibleguy.opnsense 1.2.1  

M601153-2:~ richard.fry$ python3 -m pip list | grep ansible
ansible      2.10.7
ansible-base 2.10.5

Thanks, Richard

Hi.

Ansible version 2.10 is pretty old.
See: versions

Please try updating it:

pip install --upgrade ansible

- AnsibleGuy

Looks to be the same error after upgrade.

The full traceback is:
Traceback (most recent call last):
  File "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/task_executor.py", line 158, in run
    res = self._execute()
  File "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/task_executor.py", line 663, in _execute
    result = self._handler.run(task_vars=variables)
  File "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/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 "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/module_common.py", line 812, in __init__
    self._locate()
  File "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/module_common.py", line 706, in _locate
    if self._find_module(candidate_name_parts):
  File "/Users/richard.fry/Library/Python/3.8/lib/python/site-packages/ansible/executor/module_common.py", line 832, in _find_module
    src = pkgutil.get_data(collection_pkg_name, to_native(os.path.join(resource_base_path, '__init__.py')))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pkgutil.py", line 619, in get_data
    spec = importlib.util.find_spec(package)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/util.py", line 114, in find_spec
    raise ValueError('{}.__spec__ is None'.format(name))
ValueError: ansible_collections.ansibleguy.opnsense.__spec__ is None
fatal: [10.40.0.11]: FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""

Richard

Hi.
I don't think this is an issue of the collection as it does work on so many systems without this error occurring.

But this issue seems to appear in a few cases for multiple collections - see: ansible/ansible#68361

Yes - maybe try using another collection like community.general to check if any works on you system/setup.
But you might need to troubleshoot it yourself.
I don't see this being a problem of this collection/modules.

-AnsibleGuy