Sample Header Ad - 728x90

If condition in ansible jinja2 template

3 votes
1 answer
3108 views
Search keyword in "host_fqdn" variable. If the value has "lab.com" keyword in it, it should directly store the value to "host_fqdn" again or else it should add "lab.com" keyword to the value and store it to "host_fqdn" variable. vars: host_fqdn: server host_fqdn: | {% if 'lab.com' in {{ host_fqdn }} %} {% host_fqdn = "{{ host_fqdn }}" %} {% else %} {% host_fqdn = "{{ host_fqdn }}.lab.com" %} {% endif %}
Asked by Pandu (149 rep)
Feb 19, 2019, 03:42 PM
Last activity: Jan 28, 2025, 09:06 PM