Hello Ansiblers!
I was trying to think of a way to expose multiple ports in a row by using the docker module (
http://docs.ansible.com/ansible/docker_module.html) but I can't think of anything except looping through the values I would need by means of the usual
with_items way, which is not what I want because it would result in an overwrite of the previous iteration.My scenario is as follows:
tasks:
- name: Install Nginx container
docker:
name: webserver_nginx
image: nginx
state: reloaded
expose:
- "{{ ansible_docker0.ipv4.address }}:80:80"
ports:
- "{{ ansible_docker0.ipv4.address }}:80:80"
But what I want would be something like:
tasks:
- name: Install Nginx container
docker:
name: webserver_nginx
image: nginx
state: reloaded
expose:
- "{{ ansible_docker0.ipv4.address }}:80:80"
- "{{ ansible_eth0.ipv4.address }}:80:80"
- "{{ ansible_eth1.ipv4.address }}:80:80"
ports:
- "{{ ansible_docker0.ipv4.address }}:80:80"
- "{{ ansible_eth0.ipv4.address }}:80:80"
- "{{ ansible_eth1.ipv4.address }}:80:80"
Now, I know that the number of network interfaces is something that could change at some point, I was thinking to loop over the ansible_interfaces and dynamically get the ansible_{{interface}}.ipv4.address if any. But the problem remains: I would end up using a loop and running the task multiple times with a single expose/ports definition overwriting the previous ones.
Did anyone encounter this scenario so far?
How could I specify multiple expose/ports combos at once by dynamically grab the ansible_{{interface}}.ipv4.address items?
Thanks!