CRITICAL Driver 'docker' from state-file '/Users/<myusername>/.cache/molecule/ansible-role-logrotate/default/state.yml' is not available

Hello. I’ve cloned a galaxy role that I would like to add a feature to. The role is supported by a suite of tests, run using molecule. I am having problems installing/configuring the docker driver, despite following various articles (all of which essentially provide the same set of instructions for how to get molecule and its docker driver working).

I’m using MacOS M1 Silicon, and python was installed using brew.

sysctl -n machdep.cpu.brand_string
Apple M1

which python3
/opt/homebrew/bin/python3

python3 --version
Python 3.12.3

In order to run molecule against the galaxy role, from within the role’s root directory, I am using a venv:

cd ansible-role-logrotate
python3 -m  venv .venv
source .venv/bin/activate

Once the venv is activated, I then install the list of requirements, as I understand them.

(.venv) pip list
Package Version
------- -------
pip     24.0

(.venv) pip install ansible docker ansible-lint yamllint molecule molecule-plugins 'molecule-plugins[docker]'
...
Installing collected packages: resolvelib, zipp, urllib3, subprocess-tee, ruamel.yaml.clib, rpds-py, pyyaml, pygments, pycparser, pluggy, platformdirs, pathspec, packaging, mypy-extensions, mdurl, MarkupSafe, idna, filelock, click, charset-normalizer, certifi, bracex, attrs, yamllint, wcmatch, ruamel.yaml, requests, referencing, markdown-it-py, Jinja2, importlib-metadata, click-help-colors, cffi, black, rich, jsonschema-specifications, docker, cryptography, jsonschema, enrich, ansible-core, ansible-compat, ansible, molecule, ansible-lint, molecule-plugins
Successfully installed Jinja2-3.1.4 MarkupSafe-2.1.5 ansible-9.6.0 ansible-compat-24.5.1 ansible-core-2.16.7 ansible-lint-24.5.0 attrs-23.2.0 black-24.4.2 bracex-2.4 certifi-2024.2.2 cffi-1.16.0 charset-normalizer-3.3.2 click-8.1.7 click-help-colors-0.9.4 cryptography-42.0.7 docker-7.1.0 enrich-1.2.7 filelock-3.14.0 idna-3.7 importlib-metadata-7.1.0 jsonschema-4.22.0 jsonschema-specifications-2023.12.1 markdown-it-py-3.0.0 mdurl-0.1.2 molecule-24.2.1 molecule-plugins-23.5.3 mypy-extensions-1.0.0 packaging-24.0 pathspec-0.12.1 platformdirs-4.2.2 pluggy-1.5.0 pycparser-2.22 pygments-2.18.0 pyyaml-6.0.1 referencing-0.35.1 requests-2.32.2 resolvelib-1.0.1 rich-13.7.1 rpds-py-0.18.1 ruamel.yaml-0.18.6 ruamel.yaml.clib-0.2.8 subprocess-tee-0.4.1 urllib3-2.2.1 wcmatch-8.5.2 yamllint-1.35.1 zipp-3.18.2

(.venv) pip list
Package                   Version
------------------------- ---------
ansible                   9.6.0
ansible-compat            24.5.1
ansible-core              2.16.7
ansible-lint              24.5.0
attrs                     23.2.0
black                     24.4.2
bracex                    2.4
certifi                   2024.2.2
cffi                      1.16.0
charset-normalizer        3.3.2
click                     8.1.7
click-help-colors         0.9.4
cryptography              42.0.7
docker                    7.1.0
enrich                    1.2.7
filelock                  3.14.0
idna                      3.7
importlib_metadata        7.1.0
Jinja2                    3.1.4
jsonschema                4.22.0
jsonschema-specifications 2023.12.1
markdown-it-py            3.0.0
MarkupSafe                2.1.5
mdurl                     0.1.2
molecule                  24.2.1
molecule-plugins          23.5.3
mypy-extensions           1.0.0
packaging                 24.0
pathspec                  0.12.1
pip                       24.0
platformdirs              4.2.2
pluggy                    1.5.0
pycparser                 2.22
Pygments                  2.18.0
PyYAML                    6.0.1
referencing               0.35.1
requests                  2.32.2
resolvelib                1.0.1
rich                      13.7.1
rpds-py                   0.18.1
ruamel.yaml               0.18.6
ruamel.yaml.clib          0.2.8
subprocess-tee            0.4.1
urllib3                   2.2.1
wcmatch                   8.5.2
yamllint                  1.35.1
zipp                      3.18.2

At this point, the documentation that I have read suggests that the molecule, molecule-plugins, and in particular the molecule docker driver should be installed. However, when I read molecule --version the docker driver is not listed:

(.venv) molecule --version
molecule 24.2.1 using python 3.12
    ansible:2.16.7
    default:24.2.1 from molecule
    vagrant:2.0.0 from molecule_vagrant

And I think that as a result of that, when I run molecule create, I receive an error as per the title that informs me that the docker driver cannot be found:

(.venv) molecule create
CRITICAL Driver 'docker' from state-file '/Users/<myusername>/.cache/molecule/ansible-role-logrotate/default/state.yml' is not available.

I’ve run cat against the referenced file, and its contents is as follows:

(.venv) cat /Users/<myusername>/.cache/molecule/ansible-role-logrotate/default/state.yml
# Molecule managed

---
converged: false
created: false
driver: docker
is_parallel: false
molecule_yml_date_modified: 1716491367.9140189
prepared: null
run_uuid: 7662a76e-d15a-4746-b74f-a8fa65b9881c

In subsequent experiments, based on other articles I’ve found, I have also installed docker-py and even molecule-docker despite the fact that using molecule-docker seems to be deprecated in favour of molecule-plugins[docker]:

(.venv) pip install docker-py molecule-docker
...
Installing collected packages: docker-py, molecule-docker
Successfully installed docker-py-1.10.6 molecule-docker-2.1.0

(.venv) molecule --version
molecule 24.2.1 using python 3.12
    ansible:2.16.7
    default:24.2.1 from molecule
    vagrant:2.0.0 from molecule_vagrant

Lastly, I’ve also followed some other advice I found and ensured that the docker socket is available by running sudo ln -s -f /Users/<myusername>/.docker/run/docker.sock /var/run/docker.sock and also ensured that docker is running in the correct context by running docker context use default.

I’d really like to make a contribution to this galaxy role, and additionally, start to use molecule in my own workflow. However, I seem to be missing something (presumably very obvious) in what I am doing.

Could somebody put me out of my misery, please! Thank you.

I can’t comment on why molecule doesn’t work, but a general remark:

Please never install the outdated docker-py package; always use docker. The only exception is if you’re stuck with Python 2.6 or older.

(If you’ve installed docker-py you need to first uninstall it before installing docker, since both use the same library name. If you first install both and then uninstall one, the other package is left totally broken.)

2 Likes

Thanks @felixfontein - noted :slight_smile: As I mentioned in my post, I installed docker-py as part of a subsequent experiment - I was definitely at a throw stuff at the wall stage by that time, trying to get something to work!

Hopefully someone else will spot my mistake at some point. For now, I remain stuck :frowning:

I have:

molecule --version
molecule 24.2.1 using python 3.11 
    ansible:2.17.0
    azure:23.5.3 from molecule_plugins
    containers:23.5.3 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
    default:24.2.1 from molecule
    docker:23.5.3 from molecule_plugins requiring collections: community.docker>=3.4.11 ansible.posix>=1.4.0
    ec2:23.5.3 from molecule_plugins
    gce:23.5.3 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
    openstack:23.5.3 from molecule_plugins requiring collections: openstack.cloud>=2.1.0
    podman:23.5.3 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
    vagrant:23.5.3 from molecule_plugins

This is a result of using my Ansible role to install Ansible and related packages, this uses pipx to install everything.

1 Like

Excellent, @chris - thank you! I’m going to go through your role to see what, if anything I have been missing.

Can I ask, if you’re using pipx, does that mean you’re installing this directly, rather than using a venv?

1 Like

Nope, looks like you’re using a venv, defaults/main.yml · master · webarch / ansible · GitLab

Pipx creates and manages the venvs, my role could no doubt do with some improvements… there are actually two sets of tasks for pipx, one set using ansible.built.command for servers that can’t use community.general.pipx tasks for installing Ansible.

Right, libraries and other modules are injected into the ansible venv using pipx.

The way I run the role is using the ansible.sh script from the localhost repo, it only targets Debian and Ubuntu LTS as these are the only distros I use.

1 Like

Thanks @chris. I’m picking my way through your role. I’m on a mac, and so some of this is different to your approach, but I appreciate you sharing your role - it’s helping as a guide.

1 Like

The following worked for me on macOS when facing similar issues:

mkdir ~/venv
python3 -m venv ~/venv/ansible-molecule
source ~/venv/ansible-molecule/bin/activate
pip3 install molecule docker molecule-plugins[docker]

molecule --version
molecule 24.7.0 using python 3.12
ansible:2.17.2
azure:23.5.3 from molecule_plugins
containers:23.5.3 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
default:24.7.0 from molecule
docker:23.5.3 from molecule_plugins requiring collections: community.docker>=3.4.11 ansible.posix>=1.4.0
ec2:23.5.3 from molecule_plugins
gce:23.5.3 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
openstack:23.5.3 from molecule_plugins requiring collections: openstack.cloud>=2.1.0
podman:23.5.3 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
vagrant:23.5.3 from molecule_plugins