``` {% load_yaml as yaml %} test: dev: 'xxxxx' test_2: dev: 'yyyyy' {% endload %} {% set proj = slspath.split('/')[0] %} {% set env = slspath.split('/')[1] %} {% set service = slspath.split('/')[2] %} {% set a = yaml ~ '.' ~ proj ~ '.' ~ env %} test: cmd.run: - name: echo {{ a }} ``` Output: ``` test: cmd.run: - name: echo {'test': {'dev': 'xxxxx'}, 'test_2': {'dev': 'yyyyy'}}.test.dev <====================== ``` Is it possible to access test yaml from dynamically created variable? As I really want to return yaml.test.dev value no entire yaml + test.dev...
Activity
bdrx312 commentedon May 18, 2024
yamlin your example is adictionary/hashmap. You just access the value in a dictionary like you would any value in jinja.So your code should be
All of your example is just plain jinja (https://jinja.palletsprojects.com/en/3.0.x/templates/#variables) and really has nothing to with salt specifically except that it uses jinja for the default renderer.
AGirin commentedon May 20, 2024
Thanks! It works.
dwoz commentedon Oct 28, 2026
Closing — consolidated into #70585. The checkbox for this item is in the appropriate theme section of that tracker. Please pick up the sub-item there.