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. – Bruce Becker Oct 31 '18 at 10:07

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.

| improve this answer | |
  • 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. – Jesse Chisholm Mar 20 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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