I am using ansible and docker_container module. But when I start my playbook, I have error like:

"'depends_on' is not a valid attribute for a Task"

This is my playbook:

- name: Docker-compose
  hosts: localhost
  connection: local
  gather_facts: no  
    - name: Start selenium hub
        name: hub
        image: selenium:latest
        state: started
        restart: yes
          - "4444:4444"

    - name: Start chromedriver
        name: chromedriver
        image: chromedriver:latest
        state: started
        restart: yes
          - "hub"
          - "hub:hub"  
            VNC_ENABLED: true
            EXPOSE_X11: true
          - "5900:5900"

As you can see container with name 'chromedriver' depends on 'hub'. How can I do this?

  • Note that I couldn't reproduce this playbook with the images that you use as examples - perhaps they are private for you. However, there are a few public selenium and chromedriver images which you may want to use. Oct 31, 2018 at 10:07

1 Answer 1


The Ansible docker_container module indeed has no depends_on attribute. You should create the containers in order to simulate the dependency tree.

The previous task indeed does this, so just remove the depends_on attribute and the task should complete properly.

  • Whereas this does answer the OP, it makes a suggestion that needs more details. Merely creating the containers does not simulate any kind of dependency. Each service should have built in retry until its dependent services are available before continuing with their own initialization. Mar 20, 2020 at 16:53
  • It would be nice if someone could show a playbook to implement "depends_on" functionality Ex: container_A needs to up before container_B using docker_container module.
    – Shakeel
    Aug 26, 2021 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .