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

ModuleNotFoundError: No module named 'ansible.errors' #18

Closed
2 of 7 tasks
mangkoran opened this issue Jun 20, 2023 · 3 comments
Closed
2 of 7 tasks

ModuleNotFoundError: No module named 'ansible.errors' #18

mangkoran opened this issue Jun 20, 2023 · 3 comments
Labels
support Environmental problems and so on

Comments

@mangkoran
Copy link

mangkoran commented Jun 20, 2023

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.2

      (ansible-galaxy collection list | grep opnsense)

    • Ansible & Python version: 2.15.0

      (ansible --version)

  • OPNSense

    • System version: 23.1.8

    • Plugin version:

      (if applicable)

Describe the bug

Cannot run any task due to `ModuleNotFoundError: No module named 'ansible.errors'

Expected behavior

Task run successfully

Debug output

Set the debug option and copy its output.

TASK [opnsense : check opnsense items] ********************************************************************************
task path: /home/mangkoran/sch/sem-8/psm/pve-ansible/pve/roles/opnsense/tasks/main.yml:1
<10.10.1.3> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.1.3> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/mangkoran/.ansible/cp/6fe2c6f04f"' 10.10.1.3 '/bin/sh -c '"'"'echo ~root && sleep
0'"'"''
<10.10.1.3> (0, b'/root\n', b'')
<10.10.1.3> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.1.3> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/mangkoran/.ansible/cp/6fe2c6f04f"' 10.10.1.3 '/bin/sh -c '"'"'( umask 77 && mkdir
-p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265 `" && echo ansible-tmp-1687235576.8458383-27128-128500511019265="` echo /root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265 `" ) && sleep 0'"'"''
<10.10.1.3> (0, b'ansible-tmp-1687235576.8458383-27128-128500511019265=/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265\n', b'')
Using module file /home/mangkoran/.ansible/collections/ansible_collections/ansibleguy/opnsense/plugins/modules/list.py
<10.10.1.3> PUT /home/mangkoran/.ansible/tmp/ansible-local-27114japdiieu/tmp2e58stmt TO /root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py
<10.10.1.3> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/mangkoran/.ansible/cp/6fe2c6f04f"' '[10.10.1.3]'
<10.10.1.3> (0, b'sftp> put /home/mangkoran/.ansible/tmp/ansible-local-27114japdiieu/tmp2e58stmt /root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py\n', b'')
<10.10.1.3> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.1.3> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/mangkoran/.ansible/cp/6fe2c6f04f"' 10.10.1.3 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/ /root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py && sleep 0'"'"''
<10.10.1.3> (0, b'', b'')
<10.10.1.3> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.1.3> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/mangkoran/.ansible/cp/6fe2c6f04f"' -tt 10.10.1.3 '/bin/sh -c '"'"'/usr/bin/env python3 /root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py && sleep 0'"'"''
<10.10.1.3> (1, b'Traceback (most recent call last):\r\n  File "/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py", line 107, in <module>\r\n    _ansiballz_main()\r\n  File "/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File "/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py", line 47, in invoke_module\r\n    runpy.run_module(mod_name=\'ansible_collections.ansibleguy.opnsense.plugins.modules.list\', init_globals=dict(_module_fqn=\'ansible_collections.ansibleguy.opnsense.plugins.modules.list\', _modlib_path=modlib_path),\r\n  File "/usr/local/lib/python3.9/runpy.py", line 225, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File "/usr/local/lib/python3.9/runpy.py", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File "/usr/local/lib/python3.9/runpy.py", line 87,
in _run_code\r\n    exec(code, run_globals)\r\n  File "/tmp/ansible_ansibleguy.opnsense.list_payload_rodaew31/ansible_ansibleguy.opnsense.list_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/list.py", line 11, in <module>\r\n  File "<frozen zipimport>", line 259, in load_module\r\n  File "/tmp/ansible_ansibleguy.opnsense.list_payload_rodaew31/ansible_ansibleguy.opnsense.list_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/base/handler.py", line 1, in <module>\r\nModuleNotFoundError: No module named \'ansible.errors\'\r\n', b'Shared connection to 10.10.1.3 closed.\r\n')
<10.10.1.3> Failed to connect to the host via ssh: Shared connection to 10.10.1.3 closed.
<10.10.1.3> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.1.3> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/mangkoran/.ansible/cp/6fe2c6f04f"' 10.10.1.3 '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/ > /dev/null 2>&1 && sleep 0'"'"''
<10.10.1.3> (0, b'', b'')
The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py", line 107, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.ansibleguy.opnsense.plugins.modules.list', init_globals=dict(_module_fqn='ansible_collections.ansibleguy.opnsense.plugins.modules.list', _modlib_path=modlib_path),
  File "/usr/local/lib/python3.9/runpy.py", line 225, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/local/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_ansibleguy.opnsense.list_payload_rodaew31/ansible_ansibleguy.opnsense.list_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/list.py", line 11, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/ansible_ansibleguy.opnsense.list_payload_rodaew31/ansible_ansibleguy.opnsense.list_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/base/handler.py", line 1, in <module>
ModuleNotFoundError: No module named 'ansible.errors'
fatal: [opnsense1]: FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 10.10.1.3 closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1687235576.8458383-27128-128500511019265/AnsiballZ_list.py\", line 47, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.ansibleguy.opnsense.plugins.modules.list', init_globals=dict(_module_fqn='ansible_collections.ansibleguy.opnsense.plugins.modules.list', _modlib_path=modlib_path),\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 225, in run_module\r\n
return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_ansibleguy.opnsense.list_payload_rodaew31/ansible_ansibleguy.opnsense.list_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/list.py\", line 11, in <module>\r\n  File \"<frozen zipimport>\", line 259, in load_module\r\n  File \"/tmp/ansible_ansibleguy.opnsense.list_payload_rodaew31/ansible_ansibleguy.opnsense.list_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/base/handler.py\", line 1, in <module>\r\nModuleNotFoundError: No module named 'ansible.errors'\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Screenshots

Additional context

Reproduce

Tasks

Task(s) that produce the error:

- name: check opnsense items
  ansibleguy.opnsense.list:
    target: 'syslog'
    debug: true
  register: syslog

Config

Config used for the task(s):

OPNSense config

@mangkoran mangkoran added the bug Something isn't working label Jun 20, 2023
@mangkoran
Copy link
Author

mangkoran commented Jun 20, 2023

Nevermind, it seems I need to use connection: local. It is now working as expected. Thank you very much for developing this collection!

However, I am still confused on what connection: local do, compared to the default (remote I guess?) Is it because this collection manage/config the opnsense host through API (instead of in the opnsense machine directly)?

@ansibleguy
Copy link
Owner

ansibleguy commented Jun 25, 2023

Greetings @mangkoran

Glad you found the solution yourself.

The connection parameter tells Ansible where to execute the (Python3) modules.
This image showcases this behavior:
local vs remote execution

As we are managing the firewalls using HTTP REST-API there is no way for Ansible to execute these Python-Modules on the firewall directly!
In theory you could use this parameter to run all modules on a dedicated management node - so you don't have to allow network access to the firewall https-port for your (management-)clients. But I haven't had that use-case yet.

- AnsibleGuy

@ansibleguy ansibleguy added support Environmental problems and so on and removed bug Something isn't working labels Jun 25, 2023
@mikehulsman
Copy link

I am encountering the same error, using localhost as the host to execute the ansible code
Same error if I use connection: local

When using curl, I can

Collection version: 1.2.2 also tried 1.2.3 but gave the same errors
Ansible version: 2.15.2 and python :3.11.4
OPNsense 23.1

Debug output:

task path: /Users/mhulsman/Projects/home/ansible/project/opnsense/playbooks/test.yml:11
<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 /Users/mhulsman/.ansible/tmp `"&& mkdir "` echo /Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166 `" && echo ansible-tmp-1690207250.636002-53478-49311646150166="` echo /Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166 `" ) && sleep 0'
Using module file /Users/mhulsman/Projects/home/ansible/project/opnsense/collections/ansible_collections/ansibleguy/opnsense/plugins/modules/list.py
<127.0.0.1> PUT /Users/mhulsman/.ansible/tmp/ansible-local-53475c8j0arqj/tmpnyjvpkru TO /Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/ /Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/env python3 /Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.ansibleguy.opnsense.plugins.modules.list', init_globals=dict(_module_fqn='ansible_collections.ansibleguy.opnsense.plugins.modules.list', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/var/folders/6n/spmk0cv14s10d35669xt3kf00000gn/T/ansible_ansibleguy.opnsense.list_payload_7h5qw9fg/ansible_ansibleguy.opnsense.list_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/list.py", line 11, in <module>
  File "/var/folders/6n/spmk0cv14s10d35669xt3kf00000gn/T/ansible_ansibleguy.opnsense.list_payload_7h5qw9fg/ansible_ansibleguy.opnsense.list_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 "/Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py", line 107, in <module>
        _ansiballz_main()
      File "/Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/Users/mhulsman/.ansible/tmp/ansible-tmp-1690207250.636002-53478-49311646150166/AnsiballZ_list.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.ansibleguy.opnsense.plugins.modules.list', init_globals=dict(_module_fqn='ansible_collections.ansibleguy.opnsense.plugins.modules.list', _modlib_path=modlib_path),
      File "<frozen runpy>", line 226, in run_module
      File "<frozen runpy>", line 98, in _run_module_code
      File "<frozen runpy>", line 88, in _run_code
      File "/var/folders/6n/spmk0cv14s10d35669xt3kf00000gn/T/ansible_ansibleguy.opnsense.list_payload_7h5qw9fg/ansible_ansibleguy.opnsense.list_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/list.py", line 11, in <module>
      File "/var/folders/6n/spmk0cv14s10d35669xt3kf00000gn/T/ansible_ansibleguy.opnsense.list_payload_7h5qw9fg/ansible_ansibleguy.opnsense.list_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

Playbook:

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

  tasks:
    - name: pulling Aliaes
      ansibleguy.opnsense.list:
        target: 'syslog'
        debug: true
      register: existing_aliases

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

3 participants