|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # vim: ft=jinja |
3 | 3 |
|
4 | | -{%- macro deep_merge(a, b) %} |
5 | | -{#- This whole `'dict' in x.__class__.__name__` mess is a |
6 | | - workaround for the missing mapping test in CentOS 6's |
7 | | - ancient Jinja2, see #193 #} |
8 | | -{%- for k,v in b.items() %} |
9 | | -{%- if v is string or v is number %} |
10 | | -{%- do a.update({ k: v }) %} |
11 | | -{%- elif 'dict' not in v.__class__.__name__ %} |
12 | | -{%- if a[k] is not defined %} |
13 | | -{%- do a.update({ k: v }) %} |
14 | | -{%- elif a[k] is iterable and 'dict' not in a[k].__class__.__name__ and |
15 | | - a[k] is not string %} |
16 | | -{%- do a.update({ k: v|list + a[k]|list}) %} |
17 | | -{%- else %} |
18 | | -{%- do a.update({ k: v }) %} |
19 | | -{%- endif %} |
20 | | -{%- elif 'dict' in v.__class__.__name__ %} |
21 | | -{%- if a[k] is not defined %} |
22 | | -{%- do a.update({ k: v }) %} |
23 | | -{%- elif 'dict' in a[k].__class__.__name__ %} |
24 | | -{%- do a.update({ k: v }) %} |
25 | | -{%- else %} |
26 | | -{%- do deep_merge(a[k], v) %} |
27 | | -{%- endif %} |
28 | | -{%- else %} |
29 | | -{%- do a.update({ k: 'ERROR: case not contempled in merging!' }) %} |
30 | | -{%- endif %} |
31 | | -{%- endfor %} |
32 | | -{%- endmacro %} |
| 4 | +{## Start imports ##} |
| 5 | +{% import_yaml "salt/defaults.yaml" as defaults %} |
| 6 | +{% import_yaml "salt/osfamilymap.yaml" as osfamilymap %} |
| 7 | +{% import_yaml "salt/osmap.yaml" as osmap %} |
33 | 8 |
|
| 9 | +{% set lookup = salt['pillar.get']('salt:lookup', default={}, merge=True) %} |
| 10 | +{% do defaults.salt.update(lookup) %} |
34 | 11 |
|
35 | | -{## Start with defaults from defaults.yaml ##} |
36 | | -{% import_yaml "salt/defaults.yaml" as default_settings %} |
| 12 | +{# merge the osfamilymap #} |
| 13 | +{% set osfamily = salt['grains.filter_by'](osfamilymap, grain='os_family') or{} %} |
| 14 | +{% do salt['defaults.merge'](defaults['salt'], osfamily) %} |
37 | 15 |
|
38 | | -{## |
39 | | -Setup variable using grains['os_family'] based logic, only add key:values here |
40 | | -that differ from whats in defaults.yaml |
41 | | -##} |
42 | | -{% set osrelease = salt['grains.get']('osrelease') %} |
43 | | -{% set salt_release = salt['pillar.get']('salt:release', 'latest') %} |
44 | | - |
45 | | -{# All minor releases appear in an `archive` sub-directory #} |
46 | | -{% if salt_release.split('.')|length >= 3 %} |
47 | | -{% set salt_release = 'archive/' ~ salt_release %} |
48 | | -{% endif %} |
49 | | - |
50 | | -{% set os_family_map = salt['grains.filter_by']({ |
51 | | - 'Debian': { |
52 | | - 'pkgrepo': 'deb http://repo.saltstack.com/apt/' + |
53 | | - salt['grains.get']('os')|lower + '/' + salt['grains.get']('osmajorrelease', osrelease)|string + '/amd64/' + salt_release + ' ' + salt['grains.get']('oscodename') + ' main', |
54 | | - 'key_url': 'https://repo.saltstack.com/apt/' + salt['grains.get']('os')|lower + '/' + salt['grains.get']('osmajorrelease', osrelease)|string + '/amd64/' + salt_release + '/SALTSTACK-GPG-KEY.pub', |
55 | | - 'libgit2': 'libgit2-22', |
56 | | - 'pyinotify': 'python-pyinotify', |
57 | | - 'gitfs': { |
58 | | - 'pygit2': { |
59 | | - 'install_from_source': True, |
60 | | - 'version': '0.22.1', |
61 | | - 'git': { |
62 | | - 'require_state': False, |
63 | | - 'install_from_package': 'git', |
64 | | - }, |
65 | | - 'libgit2': { |
66 | | - 'install_from_source': False, |
67 | | - }, |
68 | | - }, |
69 | | - }, |
70 | | - }, |
71 | | - 'RedHat': { |
72 | | - 'pkgrepo': 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/' + salt_release, |
73 | | - 'key_url': 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/' + salt_release + '/SALTSTACK-GPG-KEY.pub', |
74 | | - 'pygit2': salt['grains.filter_by']({ |
75 | | - 'Fedora': 'python2-pygit2', |
76 | | - 'default': 'python-pygit2', |
77 | | - }, grain='os'), |
78 | | - 'python_git': 'GitPython', |
79 | | - 'gitfs': { |
80 | | - 'gitpython': { |
81 | | - 'install_from_source': False, |
82 | | - }, |
83 | | - 'pygit2': { |
84 | | - 'install_from_source': False, |
85 | | - 'git': { |
86 | | - 'require_state': False, |
87 | | - 'install_from_package': 'git', |
88 | | - }, |
89 | | - }, |
90 | | - }, |
91 | | - 'master': { |
92 | | - 'gitfs_provider': 'pygit2' |
93 | | - }, |
94 | | - }, |
95 | | - 'Suse': { |
96 | | - 'pygit2': 'python-pygit2', |
97 | | - 'pyinotify': 'python-pyinotify', |
98 | | - 'gitfs': { |
99 | | - 'pygit2': { |
100 | | - 'install_from_source': False, |
101 | | - 'git': { |
102 | | - 'require_state': False, |
103 | | - 'install_from_package': 'git', |
104 | | - }, |
105 | | - }, |
106 | | - }, |
107 | | - 'master': { |
108 | | - 'gitfs_provider': 'pygit2' |
109 | | - }, |
110 | | - }, |
111 | | - 'Gentoo': { |
112 | | - 'salt_master': 'app-admin/salt', |
113 | | - 'salt_minion': 'app-admin/salt', |
114 | | - 'salt_syndic': 'app-admin/salt', |
115 | | - 'salt_api': 'app-admin/salt', |
116 | | - 'salt_cloud': 'app-admin/salt', |
117 | | - 'pyinotify': 'dev-python/pyinotify', |
118 | | - }, |
119 | | - 'Arch': { |
120 | | - 'salt_master': 'salt', |
121 | | - 'salt_minion': 'salt', |
122 | | - 'salt_syndic': 'salt', |
123 | | - 'salt_cloud': 'salt', |
124 | | - 'salt_api': 'salt', |
125 | | - 'salt_ssh': 'salt', |
126 | | - 'python_git': 'python2-gitpython', |
127 | | - 'pygit2': 'python2-pygit2', |
128 | | - 'libgit2': 'libgit2', |
129 | | - 'pyinotify': 'python2-pyinotify', |
130 | | - }, |
131 | | - 'Alpine': { |
132 | | - 'salt_master': 'salt-master', |
133 | | - 'salt_minion': 'salt-minion', |
134 | | - 'salt_syndic': 'salt-syndic', |
135 | | - 'salt_cloud': 'salt-cloud', |
136 | | - 'salt_api': 'salt-api', |
137 | | - 'salt_ssh': 'salt-ssh', |
138 | | - 'pygit2': 'py2-pygit2', |
139 | | - 'libgit2': 'libgit2', |
140 | | - }, |
141 | | - 'FreeBSD': { |
142 | | - 'salt_master': 'py27-salt', |
143 | | - 'salt_minion': 'py27-salt', |
144 | | - 'salt_syndic': 'py27-salt', |
145 | | - 'salt_cloud': 'py27-salt', |
146 | | - 'salt_api': 'py27-salt', |
147 | | - 'salt_ssh': 'py27-salt', |
148 | | - 'python_git': 'py27-GitPython', |
149 | | - 'pygit2': 'py27-pygit2', |
150 | | - 'config_path': '/usr/local/etc/salt', |
151 | | - 'minion_service': 'salt_minion', |
152 | | - 'master_service': 'salt_master', |
153 | | - 'api_service': 'salt_api', |
154 | | - 'syndic_service': 'salt_syndic', |
155 | | - }, |
156 | | - 'OpenBSD': { |
157 | | - 'salt_master': 'salt', |
158 | | - 'salt_minion': 'salt', |
159 | | - 'salt_syndic': 'salt', |
160 | | - 'salt_cloud': 'salt', |
161 | | - 'salt_api': 'salt', |
162 | | - 'salt_ssh': 'salt', |
163 | | - 'config_path': '/etc/salt', |
164 | | - 'minion_service': 'salt_minion', |
165 | | - 'master_service': 'salt_master', |
166 | | - 'python_git': 'py-GitPython', |
167 | | - }, |
168 | | - 'Windows': { |
169 | | - 'salt_minion': 'salt-minion', |
170 | | - 'config_path': 'C:\salt\conf', |
171 | | - 'minion_service': 'salt-minion', |
172 | | - }, |
173 | | - 'MacOS': { |
174 | | - 'salt_minion': 'com.saltstack.salt', |
175 | | - 'salt_minion_pkg_source': '', |
176 | | - 'salt_minion_pkg_hash': '', |
177 | | - 'config_path': '/private/etc/salt', |
178 | | - 'minion_service': 'com.saltstack.salt.minion', |
179 | | - }, |
180 | | - }, merge=salt['grains.filter_by']({ |
181 | | - 'Ubuntu': { |
182 | | - 'pkgrepo': 'deb http://repo.saltstack.com/apt/' + |
183 | | - salt['grains.get']('os')|lower + '/' + osrelease + '/amd64/' + salt_release + ' ' + salt['grains.get']('oscodename') + ' main', |
184 | | - 'key_url': 'https://repo.saltstack.com/apt/' + salt['grains.get']('os')|lower + '/' + osrelease + '/amd64/' + salt_release + '/SALTSTACK-GPG-KEY.pub', |
185 | | - 'pygit2': 'python-pygit2', |
186 | | - 'gitfs': { |
187 | | - 'pygit2': { |
188 | | - 'install_from_source': False, |
189 | | - 'git': { |
190 | | - 'require_state': False, |
191 | | - 'install_from_package': None, |
192 | | - }, |
193 | | - }, |
194 | | - }, |
195 | | - }, |
196 | | - 'Raspbian': { |
197 | | - 'pkgrepo': 'deb http://repo.saltstack.com/apt/' + |
198 | | - salt['grains.get']('os_family')|lower + '/' + salt['grains.get']('osmajorrelease', osrelease)|string + '/armhf/' + salt_release + ' ' + salt['grains.get']('oscodename') + ' main', |
199 | | - 'key_url': 'https://repo.saltstack.com/apt/' + salt['grains.get']('os_family')|lower + '/' + salt['grains.get']('osmajorrelease', osrelease)|string + '/armhf/' + salt_release + '/SALTSTACK-GPG-KEY.pub', |
200 | | - }, |
201 | | - 'SmartOS': { |
202 | | - 'salt_master': 'salt', |
203 | | - 'salt_minion': 'salt', |
204 | | - 'salt_syndic': 'salt', |
205 | | - 'salt_cloud': 'salt', |
206 | | - 'salt_api': 'salt', |
207 | | - 'salt_ssh': 'salt', |
208 | | - 'minion_service': 'salt:minion', |
209 | | - 'master_service': 'salt:master', |
210 | | - 'api_service': 'salt:api', |
211 | | - 'python_dulwich': 'py27-dulwich', |
212 | | - 'gitfs': { |
213 | | - 'dulwich': { |
214 | | - 'install_from_source': False, |
215 | | - } |
216 | | - }, |
217 | | - 'config_path': '/opt/local/etc/salt', |
218 | | - 'master': { |
219 | | - 'gitfs_provider': 'dulwich' |
220 | | - }, |
221 | | - } |
222 | | - }, grain='os', merge=salt['pillar.get']('salt:lookup'))) |
223 | | -%} |
224 | | - |
225 | | -{## Merge the flavor_map to the default settings ##} |
226 | | -{% do deep_merge(default_settings.salt,os_family_map) %} |
| 16 | +{# merge the osmap #} |
| 17 | +{% set osmap = salt['grains.filter_by'](osmap, grain='os') or{} %} |
| 18 | +{% do salt['defaults.merge'](defaults['salt'], osmap) %} |
227 | 19 |
|
228 | 20 | {## Merge in salt pillar ##} |
229 | | -{% set salt_settings = salt['pillar.get']( |
230 | | - 'salt', |
231 | | - default=default_settings.salt, |
232 | | - merge=True) |
233 | | -%} |
| 21 | +{% set salt_settings = salt['pillar.get']('salt', default=defaults['salt'], merge=True) %} |
234 | 22 |
|
235 | 23 | {## Merge in salt_formulas pillar ##} |
236 | | -{% set formulas_settings = salt['pillar.get']( |
237 | | - 'salt_formulas', |
238 | | - default=default_settings.salt_formulas, |
239 | | - merge=True) |
240 | | -%} |
| 24 | +{% set formulas_settings = salt['pillar.get']('salt_formulas',default=defaults['salt_formulas'], merge=True) %} |
0 commit comments