jinja2 - how to access pillar data with variables? -


i have pillar data set this;

vlan_tag_id:   nginx: 1   apache: 2   mp: 3   redis: 4 

in formula sls file this;

{% set tag = pillar.get('vlan_tag_id', 'u') %} 

so have variable tag dictionary {'apache': 2, 'nginx': 1, 'redis': 4, 'mp': 3}

at run time pass pillar data app value either

1. apache 2. nginx 3. redis 4. mp 

so if @ run time pass apache want me value 2

i cant {{ salt['pillar.get']('vlan_tag_id:app', '')}} because app variable.

i tried doing {{ salt'pillar.get'}}, throws error.

how can ?

since tag dictionary, can on well:

{%- set tag = pillar.get('vlan_tag_id', 'u') %} {%- set app = pillar.get('app') %} {{ tag.get(app) }} # note lack of quotes 

if want use colon syntax, can append contents of app key string:

{%- set app = pillar.get('app') %} {{ salt['pillar.get']('vlan_tab_id:' + app) }} 

i find simpler follow if alias pillar.get , break bit:

{%- set pget = salt['pillar.get'] %} {%- set app = pget('app')         %} {%- set tag = pget('vlan_tag_id') %} {{ tag.get(app) }} 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -