Container deployment sync problem with Ansible



  • 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)



  • You want the https://docs.ansible.com/ansible/latest/collections/ansible/builtin/wait_for_module.html#ansible-collections-ansible-builtin-wait-for-module or 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.




Suggested Topics

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