Molecule - Setup, documentation, and testing

I’m hoping to be able to get some assistance with configuring Molecule 6, as the documentation page is either lacking or I’m not understanding it.

After creating the molecule/default directory and the files inside using the molecule init scenario --driver-name docker command, running molecule create will supposedly create the container, but it is no listed with docker ps and molecule login returns a FileNotFoundError for instance_config.yml.

Looking at the create.yml file there are some comments that state that some editing of the file is required, but the documentation page does not indicate what this is.

What am I missing here? Trying the same thing with Molecule 5.1.0 actually creates the container and molecule login connects to it.

1 Like

Hi @TheSpy0, there are a few changes to Molecule 6 regarding the drivers. The documentation is a work in progress as the Molecule 6 release could be considered something of an early preview right now.

There is an upcoming blog post by @ansibehl about it, although it might not be spot on for your issue, he might be able to chime in with the specifics here, I think the drivers were split from the default molecule install.

You can check the following Github issue to see some of the details behind the upcoming changes, where you will find @tima, @cidrblock and @ssbarnea talking about them.

1 Like

Hi @Leo . Thanks for linking that Github issue.

If I’m understanding correctly, the generated create.yml, destroy.yml, and converge.yml files can be discarded and replaced with something like the Using Docker containers example provided in the Molecule documentation, or at least this is the direction things are probably going.

Looking forward to the blog post by @ansibehl as well.


create.yml, destroy.yml, prepare.yml, … are playbooks for specific molecule steps of your scenario; in most cases, you only need the converge.yml one.

Containers / instances definition is in molecule.yml file, platforms key; exemple:

  name: docker
  - name: test_dst_netbox_dind_${MOLECULE_SCENARIO_NAME}
    hostname: test_dst_netbox_dind_${MOLECULE_SCENARIO_NAME}
    image: ptouron/ansible-molecule:dind-latest
    privileged: true
    pre_build_image: true
    override_command: false

Then you can run molecule converge [-s <scenarioName>] to apply tasks from converge.yml (usually a simple playbook to apply the role you’re testing), which will create instances, lint if you have that configured, prepare if you defined prepare tasks in prepare.yml playbook, then apply tasks from converge.yml playbook on defined instances. Or just specified steps you which to use (and that you can cherry-pick for specified scenarios).

Last thing, IIRC you also have to install pip package ‘molecule-docker’ to use docker driver with molecule, though I’m not sure it’s still relevant as doc is stating these packages are now to be installed as plugins, so ‘molecule-plugins[docker]’.

I hope it makes sense; if not, don’t hesitate to @me and I’ll try to provide better examples.


@TheSpy0 Nice to meet you virtually!!
The blog on molecule 6 is released now, although it doesn’t answer your exact question, you will get a good idea on where the molecule project is headed and what we have done to bundle it with the Ansible Automation Platform product.

Blog Link:

The big change is rely on Ansible itself to do the molecule provisioning, testing and other steps. With molecule 6 you will see change how a docker driver related scenario is initialized and change is molecule.yml file when you do a init with 5.1.0 vs v 6.0.2(latest). The documentation here will help you setup a docker related scenario using the latest version with community.docker Ansible collection.

Drivers other than delegated(default) have been made optional, but if you do a pip install molecule-plugins[docker] and then copy the scenario files(molecule,converge,verify)(yml) from v5.1.0 (init) to the v6.0.2 it should also work as you are expecting.

Let me know if this helps and give a read to the blog to understand what has changed and why the changes matter.
For any questions don’t hesitate to reach out and if you see any bugs, please open them on the molecule project.


Finally getting back to replying here.

Thank you @ansibehl . The blog post was interesting, and I’m interested in see how Molecule 6 develops in the future.

At least for now, I’m going to go back to using Molecule 5, and will mess around with Molecule 6 in my free time. Hoping the documentation will be updated soon and be a bit more clear. I’m still a bit confused with what is necessary to get the docker “driver” configured with a barebones type setup. It’s been a while since I tried, but I think I copied everything from the link you shared, but still had issues with Molecule 6 actually creating the container.