ansible-community / molecule-plugins

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

`molecule reset` requires unused module #166

Closed konstruktoid closed 1 day ago

konstruktoid commented 1 year ago

Issue Type

Molecule and Ansible details

molecule 5.0.0 using python 3.10 
    ansible:2.14.5
    azure:23.4.0 from molecule_plugins
    containers:23.4.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
    delegated:5.0.0 from molecule
    docker:23.4.0 from molecule_plugins requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
    ec2:23.4.0 from molecule_plugins
    gce:23.4.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
    podman:23.4.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
    vagrant:23.4.0 from molecule_plugins

Molecule installation method (one of):

Ansible installation method (one of):

Desired Behavior

Successful moecule reset

Actual Behaviour

Repo in question: https://github.com/konstruktoid/ansible-role-docker-rootless

$ git diff
diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml
index d75c4a0..6f80b8d 100644
--- a/molecule/default/molecule.yml
+++ b/molecule/default/molecule.yml
@@ -158,9 +158,6 @@ platforms:
     memory: 1024
 verifier:
   name: ansible
-lint: |
-  set -e
-  ansible-lint
 scenario:
   name: default
   create_sequence:
@@ -187,7 +184,6 @@ scenario:
     - destroy
   test_sequence:
     - dependency
-    - lint
     - cleanup
     - destroy
     - syntax
$ molecule test
WARNING  The scenario config file ('/home/tsj/Code/Git/ansible-role-docker-rootless/molecule/default/molecule.yml') has been modified since the scenario was created. If recent changes are important, reset the scenario with 'molecule destroy' to clean up created items or 'molecule reset' to clear current configuration.
[...]
$ grep -A3 driver molecule/default/molecule.yml 
driver:
  name: vagrant
  provider:
    name: virtualbox
$ molecule reset
WARNING  The scenario config file ('/home/tsj/Code/Git/ansible-role-docker-rootless/molecule/default/molecule.yml') has been modified since the scenario was created. If recent changes are important, reset the scenario with 'molecule destroy' to clean up created items or 'molecule reset' to clear current configuration.
WARNING  vagrant driver is not installed.
INFO     default scenario test matrix: 
INFO     Performing prerun with role_name_check=0...
INFO     Running ansible-galaxy collection install -v -r requirements.yml
INFO     Set ANSIBLE_LIBRARY=/home/tsj/.cache/ansible-compat/ca6d44/modules:/home/tsj/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_ROLES_PATH=/home/tsj/.cache/ansible-compat/ca6d44/roles:/home/tsj/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Using /home/tsj/.cache/ansible-compat/ca6d44/roles/konstruktoid.docker_rootless symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Removing /home/tsj/.cache/molecule/ansible-role-docker-rootless/default
Traceback (most recent call last):
  File "/home/tsj/Code/venvs/py310/bin/molecule", line 8, in <module>
    sys.exit(main())
  File "/home/tsj/Code/venvs/py310/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/tsj/Code/venvs/py310/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/tsj/Code/venvs/py310/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tsj/Code/venvs/py310/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tsj/Code/venvs/py310/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/tsj/Code/venvs/py310/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/tsj/Code/venvs/py310/lib/python3.10/site-packages/molecule/command/reset.py", line 48, in reset
    driver.reset()
  File "/home/tsj/Code/venvs/py310/lib/python3.10/site-packages/molecule_plugins/docker/driver.py", line 256, in reset
    import docker
ModuleNotFoundError: No module named 'docker'
ssbarnea commented 1 year ago

That looks like a bug in molecule-plugins, it should do lazy imports as dependencies are not always installed.

Maybe we should ignore (or warn) about plugins that cannot be instantiated? Any suggestions?

konstruktoid commented 1 year ago

Maybe just information that "No module named 'docker' is installed." since I assume it would be noticeable if the module wasn't installed but expected to be used the the molecule tests

theonejj commented 1 year ago

This issue should be fixed when molecule#2540 is closed

EDIT: you can do it manually by removing the ~/.cache/molecule/ and remove all the things created by the driver, vagrant will do that in the destroy playbook