I am trying to write a playbook that will download a docker image and run it on a group of servers. I have a python 3.6 virtualenv created and installed ansible into it. I then ran:

ansible-galaxy collections install community.docker

I verified that the collection was downloaded and is in my .ansible/collections/ansible_collections folder.

My playbook looks like:

    - name: test docker
      hosts: all
        - community.docker
      become: true
        - name: log into the ocir registry
            registry_url: "{{ ocir_registry }}"
            username: "{{ docker_user }}"
            password: "{{ ocir_auth_token }}"
            state: present
        - name: ensure a container is running
            name: LDAPServer
            state: started
            image: "{{ docker_image }}"
            pull: true
            restart_policy: always
              - "3000:3000"

When I run this playbook with:

    ansible-playbook docker.yml

I keep getting the following error:

        ayload.zip/ansible_collections/community/docker/plugins/module_utils/common.py", line 33, 
        in <module>
        from docker import __version__ as docker_version
    ImportError: No module named docker

I just double-checked and I did install docker in my virtualenv, and I have the virtualenv activated when running the playbook.

What am I doing wrong, or haven't I done to set things up correctly?

1 Answer 1


In order to use the Docker Ansible modules, you need the Python docker module installed.

See the Ansible Docker requirements:

Most of the modules and plugins in community.docker require the Docker SDK for Python. The SDK needs to be installed on the machines where the modules and plugins are executed, and for the Python version(s) with which the modules and plugins are executed.

So you need to do a pip install docker (assuming python3) before using the community.docker collection.

  • After activating my virtualenv, I ran pip install --force docker, and the docker module was re-installed. I then tried running my playbook but got the same importerror. I also tried running python interpreter and importing docker and it worked fine. Is there something else I can do to get this to work?
    – dnraikes
    Mar 28, 2022 at 1:14
  • I started fresh with a new compute instance as my ansible manager. I used pip3 to install ansible, docker, and oci, and verified that both the oci and docker modules could be loaded in the python interactive interpreter. I then reran my playbook and still get the same error. python 3.6.8, docker module 5.0.3 ansible 2.11.9.
    – dnraikes
    Mar 28, 2022 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.