# Ansible docker module: expose multiple \<IPv4\>:\<port\>:\<port\> combos at once

**URL:** <https://forum.ansible.com/t/ansible-docker-module-expose-multiple-ipv4-port-port-combos-at-once/21036>\
**Category:** Ansible Project\
**Created:** [March 31, 2016, 7:49pm UTC](https://forum.ansible.com/t/ansible-docker-module-expose-multiple-ipv4-port-port-combos-at-once/21036 "2016-03-31T19:49:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walter\_Dolce](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@Walter\_Dolce](https://forum.ansible.com/u/Walter_Dolce)\
**Post date:** [March 31, 2016, 7:49pm UTC](https://forum.ansible.com/t/ansible-docker-module-expose-multiple-ipv4-port-port-combos-at-once/21036/1 "2016-03-31T19:49:41Z")

</div>

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](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:

---

<div class="post-metadata">

**Author:** ![Walter\_Dolce](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@Walter\_Dolce](https://forum.ansible.com/u/Walter_Dolce)\
**Post date:** [March 31, 2016, 10:41pm UTC](https://forum.ansible.com/t/ansible-docker-module-expose-multiple-ipv4-port-port-combos-at-once/21036/2 "2016-03-31T22:41:38Z")

</div>

I found a solution for now. I quickly wrote a filter plugin to obtain what I wanted - [https://gist.github.com/walterdolce/93a89018d69392de7c94bf690b761455](https://gist.github.com/walterdolce/93a89018d69392de7c94bf690b761455)

The final product for now is:

```auto
tasks:
   - name: Install Nginx container
     docker:
       name: webserver_nginx
       image: nginx
       state: reloaded
       expose: "{{ ansible_all_ipv4_addresses | map_ipv4_port_exports(container_port='80', host_port='80') }}"
       ports: "{{ ansible_all_ipv4_addresses | map_ipv4_port_exports(container_port='80', host_port='80') }}"

```

```auto

```

I could probably change the name of the filter to make it more docker specific.

Any feedback is more than welcome!
