! Ansible 2.0 has split functionality built in, see this example !
A simple Ansible Jinja2 filter to split a string into a list.
See the plugin documentation.
split(delimiter)
split_regex(pattern) # regex syntax is identical to Pythons
In a Jinja 2 template:
# hostname = dev.example.com
ldap_server = "dc={{ hostname | split('.') | join(',dc=') }}"
Output:
ldap_server = dc=dev,dc=example,dc=com
The same example, using split_regex:
ldap_server = "dc={{ hostname | split_regex('\.') | join(',dc=') }}"
Any improvements are welcome. This is actually my first time publishing reusable code, so any feedback on making open-source code more useful is also appreciated!