Created
November 24, 2013 16:29
-
-
Save erchn/7629017 to your computer and use it in GitHub Desktop.
auto-assign states to a minion based on cluster name if they exist on the master. The concept shamelessly copied from another community member.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# ######################################################################################### #} | |
{# ######################################################################################### #} | |
{# this block of code auto applies salt states to a given minion if they exist on the master #} | |
{% set id = grains['id'] %} | |
{# web01 host id = 'web' cluster id, allow a custom grain or pillar named 'cluster' to override #} | |
{% set cluster = salt['config.get']('cluster', id.split('.')[0].rstrip('0123456789')) %} | |
{# all available states on the master #} | |
{% set states = salt['cp.list_master']() %} | |
{% set toApply = [] %} | |
{# clusters/web/init.sls #} | |
{% if 'clusters/{0}/init.sls'.format(cluster) in states %} | |
{% if toApply.append('clusters.{0}'.format(cluster)) %} | |
{% endif %} | |
{% endif %} | |
{# clusters/web/web01.sls #} | |
{% if 'clusters/{0}/{1}.sls'.format(cluster, id) in states %} | |
{% if toApply.append('clusters.{0}.{1}'.format(cluster, id)) %} | |
{% endif %} | |
{% endif %} | |
{# if list is not empty #} | |
{% if toApply %} | |
'{{ id }}': | |
{% for a in toApply %} | |
- {{ a }} | |
{% endfor %} | |
{%- endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment