ansible-community / molecule-plugins

Collection on molecule plugins
MIT License
109 stars 73 forks source link

The error was: ModuleNotFoundError: No module named 'ansible.module_utils.common.yaml' #174

Closed dj-wasabi closed 1 year ago

dj-wasabi commented 1 year ago

I have a basic molecule setup that is using Vagrant to create a set of virtuals with Virtualbox. But when running any molecule x command, I get the following error:

$ molecule converge
WARNING  Driver vagrant does not provide a schema.
INFO     default scenario test matrix: dependency, create, prepare, converge
INFO     Performing prerun with role_name_check=0...
INFO     Set ANSIBLE_LIBRARY=/Users/wdijkerman/.cache/ansible-compat/d63f4a/modules:/Users/wdijkerman/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/Users/wdijkerman/.cache/ansible-compat/d63f4a/collections:/Users/wdijkerman/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/Users/wdijkerman/.cache/ansible-compat/d63f4a/roles:/Users/wdijkerman/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Using /Users/wdijkerman/.cache/ansible-compat/d63f4a/roles/blablabla.keycloak symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Running default > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create

PLAY [Create] ******************************************************************

TASK [Create molecule instance(s)] *********************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'ansible.module_utils.common.yaml'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/Users/wdijkerman/.ansible/tmp/ansible-tmp-1689234116.9949949-87856-202698451433494/AnsiballZ_vagrant.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/wdijkerman/.ansible/tmp/ansible-tmp-1689234116.9949949-87856-202698451433494/AnsiballZ_vagrant.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/wdijkerman/.ansible/tmp/ansible-tmp-1689234116.9949949-87856-202698451433494/AnsiballZ_vagrant.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.vagrant', init_globals=dict(_module_fqn='ansible.modules.vagrant', _modlib_path=modlib_path),\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 209, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/yy/9r83940d7xbb5_t4_h03cpt80000gn/T/ansible_vagrant_payload_2u8pq21b/ansible_vagrant_payload.zip/ansible/modules/vagrant.py\", line 33, in <module>\n  File \"/Users/wdijkerman/.venv3101/lib/python3.10/site-packages/molecule/util.py\", line 40, in <module>\n    from molecule.app import app\n  File \"/Users/wdijkerman/.venv3101/lib/python3.10/site-packages/molecule/app.py\", line 13, in <module>\n    app = App()\n  File \"/Users/wdijkerman/.venv3101/lib/python3.10/site-packages/molecule/app.py\", line 10, in __init__\n    self.runtime = Runtime(isolated=True)\n  File \"/Users/wdijkerman/.venv3101/lib/python3.10/site-packages/ansible_compat/runtime.py\", line 210, in __init__\n    from ansible.utils.display import Display\n  File \"/Users/wdijkerman/.venv3101/lib/python3.10/site-packages/ansible/utils/display.py\", line 49, in <module>\n    from ansible import constants as C\n  File \"/Users/wdijkerman/.venv3101/lib/python3.10/site-packages/ansible/constants.py\", line 12, in <module>\n    from ansible.config.manager import ConfigManager\n  File \"/Users/wdijkerman/.venv3101/lib/python3.10/site-packages/ansible/config/manager.py\", line 21, in <module>\n    from ansible.module_utils.common.yaml import yaml_load\nModuleNotFoundError: No module named 'ansible.module_utils.common.yaml'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

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

CRITICAL Ansible return code was 2, command was: ['ansible-playbook', '--inventory', '/Users/wdijkerman/.cache/molecule/keycloak/default/inventory', '--skip-tags', 'molecule-notest,notest', '/Users/wdijkerman/.venv3101/lib/python3.10/site-packages/molecule_plugins/vagrant/playbooks/create.yml']

I have updated all modules to - as far as I know - to latest versions and removed older packages (molecule-vagrant):

$ pip3 list | grep -E '(vagrant|molecule|ansible)'
ansible                           8.1.0
ansible-compat                    4.1.2
ansible-core                      2.15.1
ansible-lint                      6.17.2
molecule                          5.1.0
molecule-plugins                  23.4.1
python-vagrant                    1.0.0

This is my molecule.yml file:

---

dependency:
  name: galaxy
driver:
  name: vagrant
  provider:
    name: virtualbox
platforms:
  - name: al2-1.dev.local
    box: bento/amazonlinux-2
    memory: 1024
    cpus: 1
    groups:
      - application
    interfaces:
      - network_name: private_network
        ip: 192.168.123.3
      - network_name: forwarded_port
        guest: 8888
        host: 8888
    provider_raw_config_args:
      - "customize ['modifyvm', :id, '--natdnshostresolver1', 'on']"
  - name: al2-2.dev.local
    box: bento/amazonlinux-2
    memory: 1024
    cpus: 1
    groups:
      - backend
    interfaces:
      - network_name: private_network
        ip: 192.168.123.4
    provider_raw_config_args:
      - "customize ['modifyvm', :id, '--natdnshostresolver1', 'on']"
  - name: database.dev.local
    box: bento/amazonlinux-2
    memory: 1024
    cpus: 1
    groups:
      - database
    interfaces:
      - network_name: private_network
        ip: 192.168.123.10
    provider_raw_config_args:
      - "customize ['modifyvm', :id, '--natdnshostresolver1', 'on']"
provisioner:
  name: ansible
  inventory:
    host_vars:
      al2-1.dev.local:
        _molecule_my_ip: 192.168.123.3
        _molecule_my_name: al2-1
        _molecule_my_hostname: al2-1.dev.local
      al2-2.dev.local:
        _molecule_my_ip: 192.168.123.4
        _molecule_my_name: al2-2
        _molecule_my_hostname: al2-2.dev.local
      database.dev.local:
        _molecule_my_ip: 192.168.123.10
        _molecule_my_name: database
        _molecule_my_hostname: database.dev.local
    group_vars:
      all:
        ansible_python_interpreter: /usr/bin/python3
        customer_cloud: vagrant
        customer_type: dev
        _postgresql_admin_password: MySecretPassword
        keycloak_database_user_admin: dbowner
        keycloak_database_host: 192.168.123.10
        keycloak_database_ssl: prefer
        keycloak_database_schema: keycloak
      backend:
        vault_database_host: database.dev.local
        vault_database_user: dbowner
        vault_database_password: MySecretPassword
verifier:
  name: testinfra
  options:
    v: True
    sudo: True

Anyone has an idea why this is going wrong? Did I forget something installing or removing packages? Hope to hear from you.

konstruktoid commented 1 year ago

Hi @dj-wasabi, could you test python3 -m pip install -U molecule-plugins[vagrant]@git+https://github.com/ansible-community/molecule-plugins.git 'molecule<6'?

dj-wasabi commented 1 year ago

Thank you! This works! Did I missed something in the documentation?

konstruktoid commented 1 year ago

No you didn't as far as I know, just dependencies and projects out-of-sync with eachother

dj-wasabi commented 1 year ago

Thank you!

YmClash commented 5 months ago

had the same problem