You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
only_if: "'${blah}' == 'blah' or '${blah}' == 'otherblah'"
only_if: "'${blah}' in ('blah', 'otherblah')"
Templates
==========
You can just use variables in jinja2 templates like this : ${my_variable} (attention, variables can't contain . as in my.variable !
Some default variables can be used, like {{ ansible_managed }}, $template_host, $template_uid and $template_path
a for loop :
{% for a in name_of_your_list %}
blabla
{ %endfor %}(name of your list being defined somewhere else in the vars section like name_of_your_list: [one,two,three]
{% if 'webserver' in group_names %}
# some part of a configuration file that only applies to webservers
{% endif %}
{% for host in groups['app_servers'] %}
# something that applies to all app servers.
{{ hostvars[host].ansible_eth0.ipv4.address }}
{% endfor %}
# resolv.in by {{ name | upper }}
# for {{ ansible_eth0.ipv4.address }}
{% if domain is defined -%}
domain {{ domain }}
{% endif -%}
{% for ns in resolvers -%}
nameserver {{ ns }}
{% endfor %}
{% if is_cluster_member == True %}
This machine is member of a cluster
{% else %}
{% endif %}
Using nesting variables: trying to show ansible_eth0.macaddress, but eth0 itself being a variable defined in the playbook or vars_prompt (user_interface)