<p>You want the <a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/wait_for_module.html#ansible-collections-ansible-builtin-wait-for-module" rel="nofollow noreferrer"><code>wait_for</code></a> or <a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/wait_for_connection_module.html#ansible-collections-ansible-builtin-wait-for-connection-module" rel="nofollow noreferrer"><code>wait_for_connection</code></a> modules.</p>
<p>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 <code>wait_for</code> to determine when the container is up and running -- typically by polling some health check.</p>
<p>If however your playbook consists of two plays, <em>i.e.</em></p>
<ol>
<li>Target Docker host and start container, then add the container to the inventory</li>
<li>Target the container, using the docker transport and load the data</li>
</ol>
<p>then you should use the <code>wait_for_connection</code> module.</p>
<p>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.</p>

CC BY-SA 4.0
2022-03-23T16:25:17.913Z
2022-03-23T16:25:17.913Z
Bruce Becker
<p>Imagine the following situation after you have switched from docker-compose to Ansible:</p>
<ul>
<li>You start a DB container which needs time to boot up</li>
<li>You want to load data dump into it</li>
</ul>
<p>(could be also you need to run tests after service containers are up)</p>
<p>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)</p>

<docker><ansible><containers>
Container deployment sync problem with Ansible
Ta Mu
# Container deployment sync problem with Ansible

(Asked by: username_0 on 2022-03-21)

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)

**Tags:** docker, ansible, containers


---

## 1 answers

### Answer by username_1 on 2022-03-23. Score: 1

You want the [`wait_for`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/wait_for_module.html#ansible-collections-ansible-builtin-wait-for-module) or [`wait_for_connection`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/wait_for_connection_module.html#ansible-collections-ansible-builtin-wait-for-connection-module) 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.


---

