dockermolecule

molecule 5.0.0 docker driver fails


Since last week there is a new release of molecule 5.0.0.

My CI/CD pipeline wants to use that latest version, but I've trouble with it.

  1. installation

Earlier, it was possible to run pip install molecule[docker] to install all necessary libraries. But this fails with WARNING: molecule 5.0.0 does not provide the extra 'docker'.

So I switched to pip install molecule-docker, which works and molecule drivers shows that docker driver is available.

$ molecule --version
molecule 5.0.0 using python 3.11 
    ansible:2.14.5
    delegated:5.0.0 from molecule
    docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
$ molecule drivers
  delegated                                                                     
  docker 
  1. run

But when I run molecule test, I'm getting a real big stack trace, saying that a driver.json file is missing within the molecule-docker package:

$ molecule test
Traceback (most recent call last):
  File "/usr/local/bin/molecule", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/molecule/command/test.py", line 113, in test
    base.execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args)
  File "/usr/local/lib/python3.11/site-packages/molecule/command/base.py", line 94, in execute_cmdline_scenarios
    get_configs(args, command_args, ansible_args, glob_str),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/molecule/command/base.py", line 185, in get_configs
    configs = [
              ^
  File "/usr/local/lib/python3.11/site-packages/molecule/command/base.py", line 186, in <listcomp>
    config.Config(
  File "/usr/local/lib/python3.11/site-packages/molecule/config.py", line 64, in __call__
    obj.after_init()
  File "/usr/local/lib/python3.11/site-packages/molecule/config.py", line 118, in after_init
    self._validate()
  File "/usr/local/lib/python3.11/site-packages/molecule/config.py", line 456, in _validate
    errors = schema_v3.validate(self.config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/molecule/model/schema_v3.py", line 61, in validate
    with open(schema_file, encoding="utf-8") as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.11/site-packages/molecule_docker/driver.json'

This is my molecule.yml:

---
dependency:
  name: galaxy

driver:
  name: docker

platforms:
  - name: instance1
    image: "docker.io/geerlingguy/docker-debian11-ansible"
    pre_build_image: true
    privileged: true
    cgroupns_mode: host
    command: "/lib/systemd/systemd"
    volumes:
      - "/sys/fs/cgroup:/sys/fs/cgroup:rw"
      - "/var/lib/containerd"
    tmpfs:
      - "/run"
      - "/tmp"
  - name: instance2
    image: "docker.io/geerlingguy/docker-debian11-ansible"
    pre_build_image: true
    privileged: true
    cgroupns_mode: host
    command: "/lib/systemd/systemd"
    volumes:
      - "/sys/fs/cgroup:/sys/fs/cgroup:rw"
      - "/var/lib/containerd"
    tmpfs:
      - "/run"
      - "/tmp"

provisioner:
  name: ansible
  lint:
    name: ansible-lint
  inventory:
    links:
      hosts: inventory.yml

verifier:
  name: ansible

The documentation is not really helpful anymore about how to setup the environment with docker. I've used the default settings more or less from molecule 4.x. before and there it works as expected. Is there somewhere a migration documentation available? Because the release is so young, I cannot find newer documentations.


Solution

  • Since Molecule 5, it looks like you require the molecule-plugins[docker] package instead of molecule[docker].

    Source: https://dailystuff.nl/blog/2023/switch-to-molecule-plugins