{%- set id = salt['grains.get']('id') -%} {%- set roles = salt['http.query']('http://127.0.0.1:5000/roles', decode=True, decode_type='json', params={"machine": id})['dict']['roles'] -%} {{ saltenv }}: '*': - common '{{ id }}': - ignore_missing: True - id.{{ id.replace('.', '_') }} {%- for role in roles %} - role.{{ role }} {%- endfor %}