jinja filters to iterate through IP addresses in big subnet

408 views
Skip to first unread message

Alexey Porotnikov

unread,
Jan 28, 2015, 3:30:12 PM1/28/15
to ansible...@googlegroups.com
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?

mic...@mcrilly.me

unread,
Jan 29, 2015, 4:15:36 AM1/29/15
to ansible...@googlegroups.com
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 :-)
Reply all
Reply to author
Forward
0 new messages