Imagine the following situation after you have switched from docker-compose to Ansible:

  • You start a DB container which needs time to boot up
  • You want to load data dump into it

(could be also you need to run tests after service containers are up)

How to tell Ansible that one task depends on finishing another one? (that is, also, Ansible needs to support a condition so that you tell how a task is done or not, if it's not default in a specific module)

1 Answer 1


You want the wait_for or wait_for_connection modules.

If your playbook consists of a single play, which starts the container, then loads data into it, but still targetting the docker host, then you should use wait_for to determine when the container is up and running -- typically by polling some health check.

If however your playbook consists of two plays, i.e.

  1. Target Docker host and start container, then add the container to the inventory
  2. Target the container, using the docker transport and load the data

then you should use the wait_for_connection module.

In either case it will depend somewhat on what the container does and how you know that it is ready for action. If it exposes a file, port or url then you should be able to do what you need.

Your Answer

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

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