Mimick switch statements in Jinja
What are dictionary switches?
Basic dictionary switch
{%- set mydict = {'cwm': "cwm_psa",
'datto': "datto_psa",
'halo': "halo_psa"} -%}
{%- set var1 = "datto" -%}
{{- mydict[var1] -}}Use dictionary switch with macros
{% macro split_str(item) %}
{{ item.split("_") | first |d }}
{% endmacro %}
{%- set mydict = {'cwm': split_str("cwm_psa"),
'datto': split_str("datto_psa"),
'halo': split_str("halo_psa")} -%}
{%- set var1 = "datto" -%}
{{- mydict[var1] -}}Dynamic parameter passing
Last updated
Was this helpful?
