ansible tip: split a string on a delimiter

Osvaldo Toja
1 min readOct 26, 2017

When working with variables in Ansible, sometimes you don’t need the whole string, just a part of it.

For example, we have a variable like ansible_nodename containing the fqdn: and want to create a label with only the first part: server1

Ansible uses jinja2 for formatting so filters can be applied.

{{  ansible_nodename.split(".")[0] | lower }}