-
-
Save vr-jack/d53733b554fb15b12bfd to your computer and use it in GitHub Desktop.
Yaml load for pillar top.sls
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
hosts: | |
hgroup1: | |
host1: | |
name: host1 | |
type: vmhost | |
priority: primary | |
company: company1 | |
host2: | |
name: funbox | |
minionid: funbox-test | |
priority: primary | |
type: saltmaster | |
redrum: | |
name: redrum | |
priority: primary | |
type: vmhost | |
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
hosts: | |
hgroup2: | |
host3: | |
name: host3 | |
type: dns-auth | |
priority: primary | |
company: company1 | |
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
{% set hgroups = [] %} | |
{% set hgroup = {} %} | |
{% set hgroupL = {} %} | |
{% set stypes = [] %} | |
{% set stype = {} %} | |
{% set stypeL = {} %} | |
{% set spriorities = [] %} | |
{% set spriority = {} %} | |
{% set spriorityL = {} %} | |
{% macro gethosts(slsfile) %} | |
{% import_yaml slsfile as hostsfile %} | |
{% if hostsfile['hosts'] is defined %} | |
{% for lhgroup, cargs in hostsfile['hosts'].iteritems() %} | |
{% for host, args in hostsfile['hosts'][lhgroup].iteritems() %} | |
{% if args['minionid'] is defined %} | |
{% set minionid = args['minionid'] %} | |
{% else %} | |
{% if args['type'] is defined and args['priority'] is defined %} | |
{% if args['name'] is defined %} | |
{% set lname = args['name'] %} | |
{% else %} | |
{% set lname = host %} | |
{% endif %} | |
{% set minionid = [ lname,args['type'],args['priority'], | |
lhgroup ]|join('-') %} | |
{% else %} | |
{% set minionid = host %} | |
{% endif %} | |
{% endif %} | |
{% if lhgroup not in hgroups %} | |
{% do hgroups.append(lhgroup) %} | |
{% endif %} | |
{% if hgroup[lhgroup] is not defined %} | |
{% do hgroup.update({lhgroup : [] }) %} | |
{% endif %} | |
{% do hgroup[lhgroup].append(minionid) %} | |
{% if args['type'] is defined %} | |
{% if args['type'] not in stypes %} | |
{% do stypes.append(args['type']) %} | |
{% endif %} | |
{% if stype[args['type']] is not defined %} | |
{% do stype.update({args['type'] : [] }) %} | |
{% endif %} | |
{% do stype[args['type']].append(minionid) %} | |
{% endif %} | |
{% if args['priority'] is defined %} | |
{% if args['priority'] not in spriorities %} | |
{% do spriorities.append(args['priority']) %} | |
{% endif %} | |
{% if spriority[args['priority']] is not defined %} | |
{% do spriority.update({args['priority'] : [] }) %} | |
{% endif %} | |
{% do spriority[args['priority']].append(minionid) %} | |
{% endif %} | |
{% endfor %} | |
{% endfor %} | |
{% endif %} | |
{% endmacro %} | |
{% for value in salt['file.readdir']('/srv/pillar') %} | |
{% if salt['file.file_exists']('/srv/pillar/' ~value ~ '/hosts.sls') %} | |
{% do gethosts(value ~ '/hosts.sls') %} | |
{% endif %} | |
{% endfor %} | |
{% for value in stypes %} | |
{% do stypeL.update({value : 'L@' ~ stype[value]|join(',')}) %} | |
{% endfor %} | |
{% for value in spriorities %} | |
{% do spriorityL.update({value : 'L@' ~ spriority[value]|join(',')}) %} | |
{% endfor %} | |
{% for value in hgroups %} | |
{% do hgroupL.update({value : 'L@' ~ hgroup[value]|join(',')}) %} | |
{% endfor %} |
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
base: | |
{% from 'hostsimport.jinja' import hgroups,hgroupL,stypeL,spriorityL with context %} | |
{% for hgroup in hgroups %} | |
{{hgroupL[hgroup]}}: | |
- match: compound | |
- {{hgroup}}.hosts | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment