# Missing a split function in Jinja

**URL:** <https://forum.ansible.com/t/missing-a-split-function-in-jinja/17806>\
**Category:** Ansible Developer\
**Created:** [March 22, 2015, 3:15pm UTC](https://forum.ansible.com/t/missing-a-split-function-in-jinja/17806 "2015-03-22T15:15:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Ogenstad](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@Patrick\_Ogenstad](https://forum.ansible.com/u/Patrick_Ogenstad)\
**Post date:** [March 22, 2015, 3:15pm UTC](https://forum.ansible.com/t/missing-a-split-function-in-jinja/17806/1 "2015-03-22T15:15:57Z")

</div>

Hi,

I’m setting up a new test network and had some plans for how I wanted to setup DNS. However I ran into a brick wall since Jinja doesn’t have a split function.

However I found that Ansible has it’s own Jinja functions and I added a simple function to ansible/runner/filter\_plugins/core.py:

def get\_shard(a, separator, index):  
values = a.split(separator)  
index = int(index)  
return values[index]

(then added it under filters in the FilterModule class within that core.py file).

This solved my problem but I don’t know if this is the right place for such code, or if the function has the best name. However I would like to see this in Ansible in the future. Would you accept a filter like this in core.py? If not could it be submitted somewhere else?

So what I wanted was to be able to create a vars file as below to be able to create DNS entries under a specific domain and automatically create the reverse DNS entry.

This is my vars file:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 22, 2015, 4:01pm UTC](https://forum.ansible.com/t/missing-a-split-function-in-jinja/17806/2 "2015-03-22T16:01:07Z")

</div>

Because jinja2 variables are Python objects, they also carry the methods of the Python object. As such you can use .split() directly in a playbook/template such as:

domain[forward][‘hosts’][host][‘ip’].split(‘.’)[0]

---

<div class="post-metadata">

**Author:** ![Patrick\_Ogenstad](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@Patrick\_Ogenstad](https://forum.ansible.com/u/Patrick_Ogenstad)\
**Post date:** [March 22, 2015, 4:26pm UTC](https://forum.ansible.com/t/missing-a-split-function-in-jinja/17806/3 "2015-03-22T16:26:44Z")

</div>

Ah, cool. Thanks Matt! I’ll use that instead.
