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

[General] - No module named 'ansible.errors' #24

Closed
2 tasks
mikehulsman opened this issue Jul 25, 2023 · 3 comments
Closed
2 tasks

[General] - No module named 'ansible.errors' #24

mikehulsman opened this issue Jul 25, 2023 · 3 comments
Assignees
Labels
support Environmental problems and so on

Comments

@mikehulsman
Copy link

Tasks

Please make sure to go through these steps before opening an issue:

  • [ ✅] Read the documentation of the affected module: Docs

  • [ ✅] Read the troubleshooting info: Info

Basic info

  • Affected Module:

Versions

  • Controller

    • [ ✅] Collection version: 1.2.3

      (ansible-galaxy collection list | grep opnsense)

    • [:white_check_mark: ] Ansible & Python version:
      ansible [core 2.15.0]
      config file = /home/mhulsman/ansible/project/opnsense/ansible.cfg
      configured module search path = ['/home/mhulsman/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/lib/python3.11/site-packages/ansible
      ansible collection location = /home/mhulsman/ansible/project/opnsense/collections
      executable location = /usr/bin/ansible
      python version = 3.11.4 (main, Jun 30 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3.11)
      jinja version = 3.1.2
      libyaml = True

      (ansible --version)

  • OPNSense

    • [:white_check_mark: ] System version: 23.1

    • Plugin version:

      (if applicable)

Describe the bug

Cannot run any task due to the error: ModuleNotFoundError: No module named 'ansible.errors'
I found Issue #18 but that is not solving my problems.
I use localhost as executioner, that did not work
Also using connection: local that also did not work
Firewall as FQDN or IP number, the same error
I have httpx installed
When using curl to list aliases I get the proper output.
Used the downloaded apikey.txt and even used the api_key and api_secret

Expected behavior

working modules

Debug output

Set the debug option and copy its output.

TASK [pulling Aliases] ***************************************************************************************************************************************************************************************************************************
task path: /home/mhulsman/ansible/project/opnsense/playbooks/test.yml:12
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: mhulsman
<127.0.0.1> EXEC /bin/sh -c 'echo ~mhulsman && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/mhulsman/.ansible/tmp `"&& mkdir "` echo /home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026 `" && echo ansible-tmp-1690296870.3732345-6303-144439777606026="` echo /home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026 `" ) && sleep 0'
Using module file /home/mhulsman/ansible/project/opnsense/collections/ansible_collections/ansibleguy/opnsense/plugins/modules/alias.py
<127.0.0.1> PUT /home/mhulsman/.ansible/tmp/ansible-local-6299jrwgpmo6/tmp51crmd38 TO /home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/ /home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/env python3 /home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py", line 107, in <module>
    _ansiballz_main()
  File "/home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.ansibleguy.opnsense.plugins.modules.alias', init_globals=dict(_module_fqn='ansible_collections.ansibleguy.opnsense.plugins.modules.alias', _modlib_path=modlib_path),
  File "/usr/lib64/python3.9/runpy.py", line 225, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_ansibleguy.opnsense.alias_payload_ry14nyt7/ansible_ansibleguy.opnsense.alias_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/alias.py", line 10, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/ansible_ansibleguy.opnsense.alias_payload_ry14nyt7/ansible_ansibleguy.opnsense.alias_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/base/handler.py", line 1, in <module>
ModuleNotFoundError: No module named 'ansible.errors'
fatal: [localhost]: FAILED! => changed=false
  module_stderr: |-
    Traceback (most recent call last):
      File "/home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py", line 107, in <module>
        _ansiballz_main()
      File "/home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/home/mhulsman/.ansible/tmp/ansible-tmp-1690296870.3732345-6303-144439777606026/AnsiballZ_alias.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.ansibleguy.opnsense.plugins.modules.alias', init_globals=dict(_module_fqn='ansible_collections.ansibleguy.opnsense.plugins.modules.alias', _modlib_path=modlib_path),
      File "/usr/lib64/python3.9/runpy.py", line 225, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_ansibleguy.opnsense.alias_payload_ry14nyt7/ansible_ansibleguy.opnsense.alias_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/alias.py", line 10, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/ansible_ansibleguy.opnsense.alias_payload_ry14nyt7/ansible_ansibleguy.opnsense.alias_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/base/handler.py", line 1, in <module>
    ModuleNotFoundError: No module named 'ansible.errors'
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

If the issue is related to time-consumption, you may also add the content of the profiling logs.

Screenshots

Additional context

Reproduce

Tasks

Task(s) that produce the error:

- hosts: localhost
  gather_facts: no
  module_defaults:
    ansibleguy.opnsense.alias:
      firewall: 'v1fw4a01.hulsman.local'
      api_credential_file: '/home/mhulsman/ansible/project/opnsense/apikey.tx'
      ssl_verify: false

  tasks:
    - name: pulling Aliases
      ansibleguy.opnsense.alias:
        name: 'ANSIBLE_TEST1'
        content: ['1.1.1.1']
        debug: true

Config

Config used for the task(s):

- name: placeholder

OPNSense config

(If the issue only occurs when non ansible-managed config is modified)

@mikehulsman mikehulsman added the support Environmental problems and so on label Jul 25, 2023
@ansibleguy ansibleguy changed the title [Support] - ModuleNotFoundError: No module named 'ansible.errors' ebem when using localhost and/or connection:local [Support] - No module named 'ansible.errors' Jul 25, 2023
@ansibleguy ansibleguy self-assigned this Jul 25, 2023
@ansibleguy
Copy link
Owner

ansibleguy commented Jul 25, 2023

@mikehulsman I was not able to reproduce the issue, but could you try the possible fix I've implemented:

ansible-galaxy collection install git+https://github.com/ansibleguy/collection_opnsense.git

I think this happens if the execution environment can not load the Ansible core modules. (the same behavior as if the modules were run on a remote host; only 'ansible.module_utils.*' are available)
This might explain why it does not happen to everyone.
Therefor I added a 'catch' for the only 'core-import'.

Thanks

@ansibleguy ansibleguy changed the title [Support] - No module named 'ansible.errors' [General] - No module named 'ansible.errors' Jul 25, 2023
@mikehulsman
Copy link
Author

@ansibleguy

Now the module error is vanished, and the task is running fine.

Thanks for the quick reply and fixing the error

@ansibleguy
Copy link
Owner

Glad your issue could be resolved (:
Hope you find good use for the modules!

- AnsibleGuy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Environmental problems and so on
Projects
None yet
Development

No branches or pull requests

2 participants