Why can't my playbook find the community.docker modules



  • 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
          collections:
            - community.docker
          become: true
    
      tasks:
        - name: log into the ocir registry
          docker_login:
            registry_url: "{{ ocir_registry }}"
            username: "{{ docker_user }}"
            password: "{{ ocir_auth_token }}"
            state: present
    
        - name: ensure a container is running
          docker_container:
            name: LDAPServer
            state: started
            image: "{{ docker_image }}"
            pull: true
            restart_policy: always
            ports:
              - "3000:3000"
    

    When I run this playbook with:

        ansible-playbook docker.yml
    

    I keep getting the following error:

     
    "/tmp/ansible_community.docker.docker_login_payload_KMQkW7/ansible_community.docker.docker_login_p 
            ayload.zip/ansible_collections/community/docker/plugins/module_utils/common.py", line 33, 
            in 
            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?



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

    See https://docs.ansible.com/ansible/latest/collections/community/docker/docsite/scenario_guide.html#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.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2