Hi all,
I’m fairly new to Ansible and have an issue I haven’t been able to answer. I might be attacking it the wrong way, so I’d appreciate any pointers.
I have a number of docker images that need to be started, but I need to make sure the web server inside those docker containers is running before I go on to the next container.
The following is what I’m trying to achieve inside my role
---
- name: Start and wait for containers
docker: name=mydata image={{ item.name }} state=present ports={{ item.ports }}
wait_for: port={{ item.wait_for_port }}
with_items:
- { name: "service1", ports: "8080:8080", wait_for_port: 8080 }
- { name: "service2", ports: "8081:8080", wait_for_port: 8081 }
- { name: "service3", ports: "8082:8080", wait_for_port: 8082 }
It seems I can’t have 2 actions in the same task.
In the final solution the son for the items will probably be passed as an array parameter to the role.
What I need is for the each docker container to start and I then need to wait for the port to become available before moving on to the next
If I split this up into 2 tasks then all the containers will be started without the internal services necessarily becoming available.
---
- name: Start and wait for containers
docker: name=mydata image={{ item.name }} state=present ports={{ item.ports }}
with_items:
- { name: "service1", ports: "8080:8080" }
- { name: "service2", ports: "8081:8080" }
- { name: "service3", ports: "8082:8080" }
- name: Wait for ready state
wait_for: port
with_items:
- 8080
- 8081
- 8082
Any suggestions are appreciated.
Thanks