add_host for multiple containers on multiple hosts

27 views
Skip to first unread message

Jirayut Nimsaeng

unread,
May 18, 2016, 4:59:48 PM5/18/16
to Ansible Project
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?
Reply all
Reply to author
Forward
0 new messages