# add\_host for multiple containers on multiple hosts

**URL:** <https://forum.ansible.com/t/add-host-for-multiple-containers-on-multiple-hosts/21472>\
**Category:** Ansible Project\
**Created:** [May 18, 2016, 11:30am UTC](https://forum.ansible.com/t/add-host-for-multiple-containers-on-multiple-hosts/21472 "2016-05-18T11:30:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jirayut\_Nimsaeng](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@Jirayut\_Nimsaeng](https://forum.ansible.com/u/Jirayut_Nimsaeng)\
**Post date:** [May 18, 2016, 11:30am UTC](https://forum.ansible.com/t/add-host-for-multiple-containers-on-multiple-hosts/21472/1 "2016-05-18T11:30:31Z")

</div>

`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?`
