Skip to content

Commit 1d9643b

Browse files
authored
Merge pull request #395 from aboe76/simplify-map.jinja
Simplify map.jinja revert deep_merge solution from #193
2 parents 44b06d7 + 66c0699 commit 1d9643b

File tree

3 files changed

+187
-230
lines changed

3 files changed

+187
-230
lines changed

salt/map.jinja

Lines changed: 14 additions & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -1,240 +1,24 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=jinja
33

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 %}
338

9+
{% set lookup = salt['pillar.get']('salt:lookup', default={}, merge=True) %}
10+
{% do defaults.salt.update(lookup) %}
3411

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) %}
3715

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) %}
22719

22820
{## 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) %}
23422

23523
{## 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) %}

salt/osfamilymap.yaml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
4+
{% set osrelease = salt['grains.get']('osrelease') %}
5+
{% set salt_release = salt['pillar.get']('salt:release', 'latest') %}
6+
{% if salt_release.split('.')|length >= 3 %}
7+
{% set salt_release = 'archive/' ~ salt_release %}
8+
{% endif %}
9+
{% set os_lower = salt['grains.get']('os')|lower %}
10+
{% set osmajorrelease = salt['grains.get']('osmajorrelease', osrelease)|string %}
11+
{% set oscodename = salt['grains.get']('oscodename') %}
12+
13+
Debian:
14+
pkgrepo: 'deb http://repo.saltstack.com/apt/{{ os_lower }}/{{ osmajorrelease }}/amd64/{{ salt_release }} {{ oscodename }} main'
15+
key_url: 'https://repo.saltstack.com/apt/{{ os_lower }}/{{ osmajorrelease }}/amd64/{{ salt_release }}/SALTSTACK-GPG-KEY.pub'
16+
libgit2: libgit2-22
17+
pyinotify: python-pyinotify
18+
gitfs:
19+
pygit2:
20+
install_from_source: True
21+
version: 0.22.1
22+
git:
23+
require_state: False
24+
install_from_package: git
25+
libgit2:
26+
install_from_source: False
27+
28+
RedHat:
29+
pkgrepo: 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/{{ salt_release }}'
30+
key_url: 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/{{ salt_release }}/SALTSTACK-GPG-KEY.pub'
31+
pygit2: python-pygit2
32+
python_git: GitPython
33+
gitfs:
34+
gitpython:
35+
install_from_source: False
36+
pygit2:
37+
install_from_source: False
38+
git:
39+
require_state: False
40+
install_from_package: git
41+
master:
42+
gitfs_provider: pygit2
43+
44+
Suse:
45+
pygit2: python-pygit2
46+
pyinotify: python-pyinotify
47+
gitfs:
48+
pygit2:
49+
install_from_source: False
50+
git:
51+
require_state: False
52+
install_from_package: git
53+
master:
54+
gitfs_provider: pygit2
55+
56+
Gentoo:
57+
salt_master: app-admin/salt
58+
salt_minion: app-admin/salt
59+
salt_syndic: app-admin/salt
60+
salt_api: app-admin/salt
61+
salt_cloud: app-admin/salt
62+
pyinotify: dev-python/pyinotify
63+
64+
Arch:
65+
salt_master: salt
66+
salt_minion: salt
67+
salt_syndic: salt
68+
salt_cloud: salt
69+
salt_api: salt
70+
salt_ssh: salt
71+
python_git: python2-gitpython
72+
pygit2: python2-pygit2
73+
libgit2: libgit2
74+
pyinotify: python2-pyinotify
75+
76+
Alpine:
77+
salt-master: salt-master
78+
salt_minion: salt-minion
79+
salt_syndic: salt-syndic
80+
salt_cloud: salt-cloud
81+
salt_api: salt-api
82+
salt_ssh: salt-ssh
83+
pygit2: py2-pygit2
84+
libgit2: libgit2
85+
86+
FreeBSD:
87+
salt_master: py27-salt
88+
salt_minion: py27-salt
89+
salt_syndic: py27-salt
90+
salt_cloud: py27-salt
91+
salt_api: py27-salt
92+
salt_ssh: py27-salt
93+
python_git: py27-GitPython
94+
pygit2: py27-pygit2
95+
config_path: /usr/local/etc/salt
96+
minion_service: salt_minion
97+
master_service: salt_master
98+
api_service: salt_api
99+
syndic_service: salt_syndic
100+
101+
OpenBSD:
102+
salt_master: salt
103+
salt_minion: salt
104+
salt_syndic: salt
105+
salt_cloud: salt
106+
salt_api: salt
107+
salt_ssh: salt
108+
config_path: /etc/salt
109+
minion_service: salt_minion
110+
master_service: salt_master
111+
python_git: py-GitPython
112+
113+
Windows:
114+
salt_minion: salt-minion
115+
config_path: 'C:\salt\conf'
116+
minion_service: salt-minion
117+
118+
MacOS:
119+
salt_minion: com.saltstack.salt
120+
salt_minion_pkg_source: ''
121+
salt_minion_pkg_hash: ''
122+
config_path: /private/etc/salt
123+
minion_service: com.saltstack.salt.minion

0 commit comments

Comments
 (0)