# jinja filters to iterate through IP addresses in big subnet

**URL:** <https://forum.ansible.com/t/jinja-filters-to-iterate-through-ip-addresses-in-big-subnet/17394>\
**Category:** Ansible Project\
**Created:** [January 28, 2015, 8:30pm UTC](https://forum.ansible.com/t/jinja-filters-to-iterate-through-ip-addresses-in-big-subnet/17394 "2015-01-28T20:30:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey\_Porotnikov](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Alexey\_Porotnikov](https://forum.ansible.com/u/Alexey_Porotnikov)\
**Post date:** [January 28, 2015, 8:30pm UTC](https://forum.ansible.com/t/jinja-filters-to-iterate-through-ip-addresses-in-big-subnet/17394/1 "2015-01-28T20:30:12Z")

</div>

Hello.  
I’m iterating through IP addresses (crossing boundary of last octet) by writing 2 new jinja2  
filters with obvious function and content: ip2int and int2ip and following code

Inventory:

[something]  
hostname1: start\_offset=200 end\_offset=399  
hostname2: start\_offset=400 end\_offset=599

Playbook:

- name: foo  
bar:  
baz: “BAZZZ={{ ((‘22.231.8.11’ | ip2int) + (item|int)) | int2ip }}”  
with\_sequence: start={{ start\_offset }} end={{ end\_offset }}

It works. Is there an easier way to do this? Or are these filters useful enough to spend time on pull request?

---

<div class="post-metadata">

**Author:** ![michael1](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@michael1](https://forum.ansible.com/u/michael1)\
**Post date:** [January 29, 2015, 9:15am UTC](https://forum.ansible.com/t/jinja-filters-to-iterate-through-ip-addresses-in-big-subnet/17394/2 "2015-01-29T09:15:35Z")

</div>

Hey,

Good work. I’d say get the filters to a standard you’re happy with and then issue a PR - it’s free to do so 🙂
