From 7ec47feaf1655e7793990665d05c1020d4b2ce4d Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Nov 11 2017 15:12:59 +0000 Subject: add macro valid_virt_cluster and use it in top.sls it returns an array with all the valid virt_clusters, as defined in pillar/valid_custom_grains.yaml --- diff --git a/pillar/macros.jinja b/pillar/macros.jinja index 3a7579c..c234db6 100644 --- a/pillar/macros.jinja +++ b/pillar/macros.jinja @@ -5,3 +5,18 @@ {% endif %} {%- endfor %} {%- endmacro %} + +{%- macro valid_virt_cluster() -%} + {%- import_yaml "valid_custom_grains.yaml" as valid_custom_grains -%} + {%- set valid_virt_cluster = [] -%} + {%- for country, data in valid_custom_grains['localized'].items() -%} + {%- if data['virt_cluster'] is iterable and data['virt_cluster'] is not string -%} + {%- for item in data['virt_cluster'] -%} + {%- do valid_virt_cluster.append(item) -%} + {%- endfor -%} + {%- else -%} + {%- do valid_virt_cluster.append(data['virt_cluster']) -%} + {%- endif -%} + {%- endfor -%} + {{ valid_virt_cluster }} +{%- endmacro -%} diff --git a/pillar/top.sls b/pillar/top.sls index ae95529..eab9795 100644 --- a/pillar/top.sls +++ b/pillar/top.sls @@ -1,4 +1,5 @@ {% from "macros.jinja" import include_optional with context %} +{% from "macros.jinja" import valid_virt_cluster with context %} {% set country = salt['grains.get']('country') %} {% set domain = salt['grains.get']('domain') %} {% set id = salt['grains.get']('id') %} @@ -17,7 +18,7 @@ production: - match: grain {{ include_optional("role/{0}".format(role)) }} {% endfor %} - {% if virt_cluster in ['atreju', 'bryce'] %} + {% if virt_cluster in valid_virt_cluster() %} 'virt_cluster:{{ virt_cluster }}': - match: grain - virt_cluster.{{ virt_cluster }}