{% set states = salt['cp.list_states'](saltenv) %} include: - roles.host.none {%- if grains['roles'] is defined -%} {%- if grains['roles'] is not none -%} {%- for role in grains['roles'] %} {%- if 'pillars.roles.host.'+role in states %} - roles.host.{{ role }} {%- endif -%} {%- endfor -%} {%- endif -%} {%- endif -%}