Skip to content

Instantly share code, notes, and snippets.

@yyq
Forked from halberom/opt1_template.j2
Created June 1, 2017 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yyq/f991281beeacdc955fdae5249436454c to your computer and use it in GitHub Desktop.
Save yyq/f991281beeacdc955fdae5249436454c to your computer and use it in GitHub Desktop.
ansible - example of template if else
{% if filepath == /var/opt/tomcat_1 %}
{% set tomcat_value == tomcat_1_value %}
{% else %}
{% set tomcat_value == tomcat_2_value %}
{% endif %}
<Server port={{ tomcat_value }} shutdown="SHUTDOWN">
---
- hosts: foo
vars:
tomcat_1_value: 'bob'
tomcat_2_value: 'bar'
tasks:
- set_fact:
tomcat_value: "{{ filepath == /var/opt/tomcat_1 | ternary(tomcat_1_value, tomcat_2_value) }}"
- template:
...
<Server port={{ tomcat_value }} shutdown="SHUTDOWN">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment