Let's see my use case
-
name: Run Nginx container
docker:
name: nginx
image: nginx
state: started
ports: -
“80:80”
-
“443:443”
-
name: Add host nginx container
add_host:
name: nginx
groups: nginx_container
ansible_connection: docker
ansible_user: root
ansible_docker_extra_args: --tlsverify --tlscacert=“{{ nginx_container_docker_cert_path }}/ca.pem” --tlscert=“{{ nginx_container_docker_cert_path }}/cert.pem” --tlskey=“{{ nginx_container_docker_cert_path }}/key.pem” -H=“{{ nginx_container_docker_host }}” -
name: Create new directory in nginx container
file:
path: /root/.ssh
state: directory
delegate_to: nginx
I have 2 hosts in inventory file to run nginx container on both hosts. Then I want to add_host for both containers to do next task that will do on both containers on both hosts.
I knew that add_host is bypass host loop but anyone know the way that I can configure container with the same name on difference host?