Repository: ansible/molecule

Issue #2540: molecule fails to reset itself when driver is changed in config
Created: 2020-02-07T11:22:41Z
I observed that molecule gets confused when a driver is swithced inside a scenario, like moving from delegated to docker casing confusing errors that do not give a hint about what caused them.
--> Action: 'destroy'
ERROR! the playbook: None could not be found

An error occurred during the test sequence action: 'destroy'. Cleaning up.
ERROR:
--> Scenario: 'foo'
--> Action: 'cleanup'
Skipping, cleanup playbook not configured.
--> Scenario: 'foo'
--> Action: 'destroy'
ERROR! the playbook: None could not be found

Funny part is that this scenario is not supposed to have these playbooks.
Removing temp files of molecule does solve the issue, but most users do not even know where these are located.
I am not yet sure how we can decide when we are in a tainted environment and to suggest performing a reset as we do want to do it by accident. Maybe timestamping molecule.yml file would be enough? When this is changed we can throw a clearly visible warning which tells user that config was tainted since last run and that they may want to do a reset if somethign fails.

Duplicate issue #3231: molecule uses docker driver instead of configured one
Created: 2021-09-06T15:01:58Z
Issue Type

Bug report

Molecule and Ansible details
ansible --version && molecule --version
ansible 2.8.20
  config file = None
  configured module search path = ['/Users/oschlueter/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/ansible
  executable location = /Users/oschlueter/git/ansible/roles/venv/bin/ansible
  python version = 3.6.14 (default, Jul 12 2021, 16:08:05) [GCC Apple LLVM 12.0.5 (clang-1205.0.22.9)]
molecule 3.4.0 using python 3.6 
    ansible:2.8.20
    delegated:3.4.0 from molecule
    ec2:0.3 from molecule_ec2
    vagrant:0.6.3 from molecule_vagrant

Molecule installation method (one of):

pip

Ansible installation method (one of):

pip

Detail any linters or test runners used:
Desired Behavior
I create an empty role with either vagrant (or ec2) as driver, invoke mol check and see that vagrant (or ec2) is used as driver:
$ mol init role nginx -d vagrant
$ cd nginx
$ mol check
# vagrant is used as driver

Actual Behaviour
Molecule attempts to use the docker driver:
$ mol --debug check
Traceback (most recent call last):
  File "/Users/oschlueter/git/ansible/roles/venv/bin/mol", line 8, in <module>
    sys.exit(main())
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/command/check.py", line 111, in check
    base.execute_cmdline_scenarios(scenario_name, args, command_args)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/command/base.py", line 98, in execute_cmdline_scenarios
    get_configs(args, command_args, ansible_args, glob_str), scenario_name
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/command/base.py", line 192, in get_configs
    for c in glob.glob(glob_str)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/command/base.py", line 192, in <listcomp>
    for c in glob.glob(glob_str)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/config.py", line 60, in __call__
    obj.after_init()
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/config.py", line 107, in after_init
    self.config = self._reget_config()
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/config.py", line 272, in _reget_config
    env = util.merge_dicts(os.environ, self.env)
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/config.py", line 190, in env
    "MOLECULE_INSTANCE_CONFIG": self.driver.instance_config,
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/config.py", line 174, in driver
    driver = api.drivers(config=self)[driver_name]
  File "/Users/oschlueter/git/ansible/roles/venv/lib/python3.6/site-packages/molecule/api.py", line 29, in __getitem__
    return self.__dict__[i]
KeyError: 'docker'

I was able to reproduce this problem with molecule versions 3.3.4 and 3.4.0 with plugins molecule-vagrant and molecule-ec2. I'm using Python 3.6.14 on a MacOS 11.5.2.

Closing comment (2021-09-09T14:08:32Z): @oschlueter Check your existing molecule variables with set | grep MOLECULE_. Somehow I have the impression you have the driver override option used, which is the only thing I know to be able to generate this kind of behavior.
Also clean molecule cache, I bet is related to #2540 -- You used docker driver at some point and later switched it, without cleaning the cache.