Missing a split function in Jinja

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:

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]

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