Skip to content

Instantly share code, notes, and snippets.

@awfki
Last active October 4, 2018 12:19
Show Gist options
  • Save awfki/9890791153e028da57d6e8e739cf5733 to your computer and use it in GitHub Desktop.
Save awfki/9890791153e028da57d6e8e739cf5733 to your computer and use it in GitHub Desktop.

Jinja2

if/elif

{% if variable == 'one' %}stuff for one
{% elif variable == 'two' %}stuff for two
{% else %}stuff for anything else
{% endif %}

Ansible

regex_search

Note: Returns a list, even if there's only one item.

sname: "{{ inventory_hostname|regex_search('^(.*?-.*?)-','\\1') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment