molecule-plugins icon indicating copy to clipboard operation
molecule-plugins copied to clipboard

"couldn't resolve module/action 'vagrant'" error when installing molecule-plugins in a fresh environment

Open garar opened this issue 11 months ago • 15 comments

Hello!

I'm trying to install molecule-plugins into fresh Python 3.12 venv using pipx (Ubuntu 24.04).

Basically what I do is:

pipx install --python python3.12 --include-deps 'molecule-plugins[vagrant,docker]'

But when I try to run molecule verify using vagrant I get:

> molecule converge && molecule verify
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     Running default > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create
ERROR! couldn't resolve module/action 'vagrant'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '/home/garar/.local/share/pipx/venvs/molecule-plugins/lib/python3.12/site-packages/molecule_plugins/vagrant/playbooks/create.yml': line 8, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks:
    - name: Create molecule instance(s) # noqa fqcn[action]
      ^ here

This is pip list output for my env:

Package                   Version
------------------------- ---------
ansible-compat            25.1.1
ansible-core              2.18.2
attrs                     25.1.0
bracex                    2.5.post1
certifi                   2025.1.31
cffi                      1.17.1
charset-normalizer        3.4.1
click                     8.1.8
click-help-colors         0.9.4
cryptography              44.0.0
distro                    1.9.0
docker                    7.1.0
enrich                    1.2.7
idna                      3.10
Jinja2                    3.1.5
jsonschema                4.23.0
jsonschema-specifications 2024.10.1
markdown-it-py            3.0.0
MarkupSafe                3.0.2
mdurl                     0.1.2
molecule                  25.2.0
molecule-plugins          23.7.0
packaging                 24.2
pip                       25.0
pluggy                    1.5.0
pycparser                 2.22
Pygments                  2.19.1
python-vagrant            1.0.0
PyYAML                    6.0.2
referencing               0.36.2
requests                  2.32.3
resolvelib                1.0.1
rich                      13.9.4
rpds-py                   0.22.3
selinux                   0.3.0
subprocess-tee            0.4.2
typing_extensions         4.12.2
urllib3                   2.3.0
wcmatch                   10.0

I'm not sure if this is a problem with molecule-plugins, or molecule itself.

I believe there is no problem with my setup in general, because if I install old ansible, molecule and molecule-plugins it does work. This is what works:

"ansible<10.0.0,>=9.1.0",
"molecule[testinfra]<7.0.0,>=6.0.3",
"molecule-plugins[vagrant]<24.0.0,>=23.5.0",
"ansible-lint>=24.10.0",

Is there some kind of compatibility matrix for molecule-plugins, molecule and ansible?

Thanks!

garar avatar Feb 02 '25 11:02 garar

I ran into this today trying to get a fresh environment going. Unfortunately the latest version of molecule seems to introduce this error. While you wait for this issue to be investigated, the following version combination got me going.

ansible>11,<12
molecule==25.1.0
molecule-plugins==23.7.0

tkimball83 avatar Feb 03 '25 01:02 tkimball83

Hi @tkimball83 !

Your combination works, thanks!

Still, it would be great to have it working by default with newest versions.

garar avatar Feb 03 '25 18:02 garar

This most likely due to https://github.com/ansible/molecule/pull/4380

hswong3i avatar Feb 05 '25 07:02 hswong3i

@hswong3i possibly. I wanted to find time to double check this assertion but failed so far. After merging the PR to use molecule >= 25.1.0, @ssbarnea mentioned that it was not necessary a good idea as there was possible breakages soon. Looks like it was sonner than I expected. We should possibly require only 25.1, while waiting for the dust to settle ?

apatard avatar Feb 05 '25 08:02 apatard

@apatard please see my comment on https://github.com/ansible/molecule/pull/4380#issuecomment-2635984988

Once I revert this PR my CI case working fine again:

  • https://github.com/alvistack/ansible-community-molecule/commit/19a4df14eb8b1a1a596c7e0b4567186b36f9ed53
  • https://build.opensuse.org/package/show/home:alvistack/ansible-community-molecule-25.2.0

hswong3i avatar Feb 05 '25 08:02 hswong3i

@tkimball83

I ran into this today trying to get a fresh environment going. Unfortunately the latest version of molecule seems to introduce this error. While you wait for this issue to be investigated, the following version combination got me going.

ansible>11,<12
molecule==25.1.0
molecule-plugins==23.7.0

Thank you so much!

I was bashing my head against the wall for hours bc I was getting one error after the error.

With you setup everything just works.

Thank you. Seriously!

sebastiankoeniggit avatar Feb 06 '25 09:02 sebastiankoeniggit

I ran into this issue too. The workaround of downgrading molecule did resolve the issue, but that's not a permanent solution.

@hswong3i 's comment brought met to https://ansible.readthedocs.io/projects/dev-tools/user-guide/test-isolation/#isolated-mode-virtual-environment-default, which states the recommended installation of molecule is through the ansible-dev-tools package.

When running the tools from ansible-dev-tools in a venv, the environment should be set automatically.

I switched my setup to use this package and now molecule+vagrant works fine, and that's with molecule 25.2.0.

Edit:

Sadly, I just found out this is not the case. I had set the ANSIBLE_LIBRARY environment variable while tinkering and that had fixed the issue. It seems this variable should point to something like <your_venv>/lib/python<version>/site-packages/molecule_plugins/vagrant/modules for molecule to pick up the Vagrant module.

matthijs-oosterhoff avatar Feb 06 '25 11:02 matthijs-oosterhoff

I ran into this today trying to get a fresh environment going. Unfortunately the latest version of molecule seems to introduce this error. While you wait for this issue to be investigated, the following version combination got me going.

ansible>11,<12
molecule==25.1.0
molecule-plugins==23.7.0

Confirmed, same issue / resolution on manjaro.

pip install --force-reinstall -v 'molecule==25.1.0' fixes for temporary workaround.

Could we also add a regression test to ensure this doesn't break on a release unintentionally again?

r-pufky avatar Feb 11 '25 19:02 r-pufky

afair, molecule is not using semver anymore. This means it can break any thing at any time. The solution would be to pin to the exact molecule version but it means missing fixes.

In terms of this particular failure, I would not be suprised of the issue not being fixed. It has been several weeks now, and no fix (unless I've missed it). Anyway, there are still plans to kill plugins: https://github.com/ansible/ansible-dev-tools/issues/510#issuecomment-2605125502 ...

I've been wondering lately about giving again a look at https://github.com/ansible-collections/community.vagrant. In the meantime, I've put the code into https://github.com/apatard/community.vagrant/tree/initial-import. Switching locally the molecule-plugins CI to this repo/branch seems to make it happy.

apatard avatar Feb 21 '25 16:02 apatard

I wrote a couple of updates that fixes my use cases;

  • https://github.com/konstruktoid/ansible-role-hardening/blob/master/generate_molecule_env.sh will generate required Molecule environmental variables, could be sourced or put in .env.yml
  • https://github.com/konstruktoid/ansible-role-hardening/blob/master/tox.ini#L16-L19 adds the Molecule env vars to the tox venvs
set_env =
    PYTHON_LIB_PATH={envdir}/lib/{basepython}/site-packages
    ANSIBLE_REMOTE_TMP=/var/tmp/${USER}/ansible
    ANSIBLE_FILTER_PLUGINS={env:PYTHON_LIB_PATH}/molecule/provisioner/ansible/plugins/filter:${HOME}/.ansible/plugins/filter:/usr/share/ansible/plugins/filter
    ANSIBLE_LIBRARY={env:PYTHON_LIB_PATH}/molecule/provisioner/ansible/plugins/modules:${PYTHON_LIB_PATH}/molecule_plugins/vagrant/modules:${HOME}/.ansible/plugins/modules:/usr/share/ansible/plugins/modules

GitHub actions: https://github.com/konstruktoid/ansible-role-hardening/actions/runs/16939056043

konstruktoid avatar Aug 13 '25 14:08 konstruktoid

I this still being worked on? I only get molecule with Vagrant running with version 25.1.0. For now this version is still working but sooner or later I guess it won't do the job anymore. Already getting quite a view warnings like

[WARNING]: Found variable using reserved name 'connection'.
Origin: /home/user/.cache/molecule/someuser.somerole/default/inventory/ansible_inventory.yml:38:7

36       ansible_ssh_user: vagrant
37       ansible_user: vagrant
38       connection: ssh
         ^ column 7

and

[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: DEFAULT_MANAGED_STR option. Reason: The `ansible_managed` variable can be set just like any other variable, or a different variable can be used.
Alternatives: Set the `ansible_managed` variable, or use any custom variable in templates. This feature will be removed from ansible-core version 2.23.

Thanks!

githubixx avatar Nov 10 '25 19:11 githubixx

I this still being worked on? I only get molecule with Vagrant running with version 25.1.0. For now this version is still working but sooner or later I guess it won't do the job anymore.

Have you tried https://github.com/ansible-community/molecule-plugins/issues/301#issuecomment-3184082904?

[WARNING]: Found variable using reserved name 'connection'.
Origin: /home/user/.cache/molecule/someuser.somerole/default/inventory/ansible_inventory.yml:38:7

https://github.com/ansible-community/molecule-plugins/pull/345

konstruktoid avatar Nov 10 '25 20:11 konstruktoid

@konstruktoid Haven't tried it yet (will do next). But the question is if this how it should be. Previously this was not necessary to set any paths. IMHO if that is needed now it'd make sense to document it maybe and close this issue. Shouldn't molecule work "out of the box" like it did the previous years (besides having the right plugins installed of course and things like that)? This issue is open for quite some time and I wonder if this really an issue or did a behavior change? Pretty confusing honestly.

githubixx avatar Nov 10 '25 23:11 githubixx

it's expected behavior after https://github.com/ansible/molecule/pull/4380

konstruktoid avatar Nov 10 '25 23:11 konstruktoid

@konstruktoid Thanks for the hint! That helped a lot 😄

Just in case someone comes across this issue: I've a Python venv running for all my Ansible roles. In that directory I'm using direnv utility to load environment variables and activate the venv automatically as soon as I enter that directory (and the env gets unloaded as soon as I leave that directory). The needed .envrc file looks like this:

export ANSIBLE_HOME="$(pwd)"

source ./bin/activate

export PYTHON_LIB_PATH="$(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')"
export ANSIBLE_LIBRARY="${PYTHON_LIB_PATH}/molecule/provisioner/ansible/plugins/modules:${PYTHON_LIB_PATH}/molecule_plugins/vagrant/modules:${HOME}/.ansible/plugins/modules:/usr/share/ansible/plugins/modules"
export ANSIBLE_FILTER_PLUGINS="${PYTHON_LIB_PATH}/molecule/provisioner/ansible/plugins/filter:${HOME}/.ansible/plugins/filter:/usr/share/ansible/plugins/filter"

That made molecule work again for me.

githubixx avatar Nov 11 '25 20:11 githubixx