Ansible templates

{% for host in groups['db_servers'] %}
{{ host }}
{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}
{% endfor %}

{% elif student.department.upper() != "MATHS DEPARTMENT" %}
Maths department
{% endif %}

# generate SSH config
{% for host in groups['vm.example.com'] %}
Host {{ host }}
Hostname {{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}
{% endfor %}

# value by group (condition)
{% if 'www' in group_names and ansible_fqdn in groups['www'] %}
foo=true
{% else %}
foo=false
{% endif %}

{% if 'index.html' in request.build_absolute_uri %}
hello
{% else %}
bye
{% endif %}

{% if grains['os'] == 'Fedora' -%}
mailq_path = /usr/bin/mailq.postfix
{% elif grains['os'] == 'Arch' -%}
mailq_path = /usr/bin/mailq
{-% endif %}

Links
http://jinja.pocoo.org/docs/dev/templates/#line-statements