ansible tip: split a string on a delimiter

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: server1.example.org 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 }}
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.