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

**URL:** <https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979>\
**Category:** Get Help\
**Tags:** docker, molecule, ansible-lint, galaxy-ng\
**Created:** [May 24, 2024, 8:53am UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979 "2024-05-24T08:53:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![danrough](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/danrough/32/3541_2.png) [@danrough](https://forum.ansible.com/u/danrough)\
**Post date:** [May 24, 2024, 8:53am UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/1 "2024-05-24T08:53:17Z")

</div>

Hello. I’ve cloned [a galaxy role](https://github.com/robertdebock/ansible-role-logrotate) 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.

```auto
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:

```auto
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.

```auto
(.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:

```auto
(.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:

```auto
(.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:

```auto
(.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]`:

```auto
(.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.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [May 24, 2024, 11:26am UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/2 "2024-05-24T11:26:20Z")

</div>

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

> [@danrough](#):
>
> `docker-py`

Please **never** install the outdated [docker-py package](https://pypi.org/project/docker-py/); always use [docker](https://pypi.org/project/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.)

---

<div class="post-metadata">

**Author:** ![danrough](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/danrough/32/3541_2.png) [@danrough](https://forum.ansible.com/u/danrough)\
**Post date:** [May 24, 2024, 12:44pm UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/3 "2024-05-24T12:44:47Z")

</div>

Thanks @felixfontein - noted 🙂 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 ☹

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [May 24, 2024, 1:08pm UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/4 "2024-05-24T13:08:18Z")

</div>

> [@danrough](#):
>
> when I read `molecule --version` the docker driver is not listed

I have:

```bash
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](https://git.coop/webarch/ansible/) to install Ansible and related packages, this uses [pipx](https://pipx.pypa.io/stable/) to install everything.

---

<div class="post-metadata">

**Author:** ![danrough](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/danrough/32/3541_2.png) [@danrough](https://forum.ansible.com/u/danrough)\
**Post date:** [May 24, 2024, 2:25pm UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/5 "2024-05-24T14:25:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![danrough](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/danrough/32/3541_2.png) [@danrough](https://forum.ansible.com/u/danrough)\
**Post date:** [May 24, 2024, 2:27pm UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/6 "2024-05-24T14:27:40Z")

</div>

> [@danrough](#):
>
> Can I ask, if you’re using pipx, does that mean you’re installing this directly, rather than using a venv?

Nope, looks like you’re using a venv, [defaults/main.yml · master · webarch / ansible · GitLab](https://git.coop/webarch/ansible/-/blob/master/defaults/main.yml?ref_type=heads#L176-181)

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [May 24, 2024, 2:29pm UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/7 "2024-05-24T14:29:25Z")

</div>

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`](https://git.coop/webarch/ansible/-/blob/master/tasks/pipx_cmd_install.yml?ref_type=heads) for servers that can’t use [`community.general.pipx` tasks for installing Ansible](https://git.coop/webarch/ansible/-/blob/master/tasks/pipx_mod_install.yml?ref_type=heads).

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [May 24, 2024, 2:30pm UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/8 "2024-05-24T14:30:29Z")

</div>

Right, libraries and other modules are [injected](https://pipx.pypa.io/stable/examples/#pipx-inject-example) into the `ansible` venv using `pipx`.

The way I run the role is using the [ansible.sh](https://git.coop/webarch/localhost/-/blob/main/ansible.sh?ref_type=heads) script from the [localhost repo](https://git.coop/webarch/localhost/-/tree/main?ref_type=heads#ansible-localhost-playbook), it only targets Debian and Ubuntu LTS as these are the only distros I use.

---

<div class="post-metadata">

**Author:** ![danrough](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/danrough/32/3541_2.png) [@danrough](https://forum.ansible.com/u/danrough)\
**Post date:** [May 24, 2024, 4:33pm UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/9 "2024-05-24T16:33:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pat-s](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pat-s/32/4242_2.png) [@pat-s](https://forum.ansible.com/u/pat-s)\
**Post date:** [July 17, 2024, 8:35pm UTC](https://forum.ansible.com/t/critical-driver-docker-from-state-file-users-myusername-cache-molecule-ansible-role-logrotate-default-state-yml-is-not-available/5979/10 "2024-07-17T20:35:50Z")

</div>

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

```auto
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

```
