Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify map.jinja revert deep_merge solution from #193 #395

Merged
merged 3 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
244 changes: 14 additions & 230 deletions salt/map.jinja
Original file line number Diff line number Diff line change
@@ -1,240 +1,24 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja

{%- macro deep_merge(a, b) %}
{#- This whole `'dict' in x.__class__.__name__` mess is a
workaround for the missing mapping test in CentOS 6's
ancient Jinja2, see #193 #}
{%- for k,v in b.items() %}
{%- if v is string or v is number %}
{%- do a.update({ k: v }) %}
{%- elif 'dict' not in v.__class__.__name__ %}
{%- if a[k] is not defined %}
{%- do a.update({ k: v }) %}
{%- elif a[k] is iterable and 'dict' not in a[k].__class__.__name__ and
a[k] is not string %}
{%- do a.update({ k: v|list + a[k]|list}) %}
{%- else %}
{%- do a.update({ k: v }) %}
{%- endif %}
{%- elif 'dict' in v.__class__.__name__ %}
{%- if a[k] is not defined %}
{%- do a.update({ k: v }) %}
{%- elif 'dict' in a[k].__class__.__name__ %}
{%- do a.update({ k: v }) %}
{%- else %}
{%- do deep_merge(a[k], v) %}
{%- endif %}
{%- else %}
{%- do a.update({ k: 'ERROR: case not contempled in merging!' }) %}
{%- endif %}
{%- endfor %}
{%- endmacro %}
{## Start imports ##}
{% import_yaml "salt/defaults.yaml" as defaults %}
{% import_yaml "salt/osfamilymap.yaml" as osfamilymap %}
{% import_yaml "salt/osmap.yaml" as osmap %}

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

{## Start with defaults from defaults.yaml ##}
{% import_yaml "salt/defaults.yaml" as default_settings %}
{# merge the osfamilymap #}
{% set osfamily = salt['grains.filter_by'](osfamilymap, grain='os_family') or{} %}
{% do salt['defaults.merge'](defaults['salt'], osfamily) %}

{##
Setup variable using grains['os_family'] based logic, only add key:values here
that differ from whats in defaults.yaml
##}
{% set osrelease = salt['grains.get']('osrelease') %}
{% set salt_release = salt['pillar.get']('salt:release', 'latest') %}

{# All minor releases appear in an `archive` sub-directory #}
{% if salt_release.split('.')|length >= 3 %}
{% set salt_release = 'archive/' ~ salt_release %}
{% endif %}

{% set os_family_map = salt['grains.filter_by']({
'Debian': {
'pkgrepo': 'deb http://repo.saltstack.com/apt/' +
salt['grains.get']('os')|lower + '/' + salt['grains.get']('osmajorrelease', osrelease)|string + '/amd64/' + salt_release + ' ' + salt['grains.get']('oscodename') + ' main',
'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',
'libgit2': 'libgit2-22',
'pyinotify': 'python-pyinotify',
'gitfs': {
'pygit2': {
'install_from_source': True,
'version': '0.22.1',
'git': {
'require_state': False,
'install_from_package': 'git',
},
'libgit2': {
'install_from_source': False,
},
},
},
},
'RedHat': {
'pkgrepo': 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/' + salt_release,
'key_url': 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/' + salt_release + '/SALTSTACK-GPG-KEY.pub',
'pygit2': salt['grains.filter_by']({
'Fedora': 'python2-pygit2',
'default': 'python-pygit2',
}, grain='os'),
'python_git': 'GitPython',
'gitfs': {
'gitpython': {
'install_from_source': False,
},
'pygit2': {
'install_from_source': False,
'git': {
'require_state': False,
'install_from_package': 'git',
},
},
},
'master': {
'gitfs_provider': 'pygit2'
},
},
'Suse': {
'pygit2': 'python-pygit2',
'pyinotify': 'python-pyinotify',
'gitfs': {
'pygit2': {
'install_from_source': False,
'git': {
'require_state': False,
'install_from_package': 'git',
},
},
},
'master': {
'gitfs_provider': 'pygit2'
},
},
'Gentoo': {
'salt_master': 'app-admin/salt',
'salt_minion': 'app-admin/salt',
'salt_syndic': 'app-admin/salt',
'salt_api': 'app-admin/salt',
'salt_cloud': 'app-admin/salt',
'pyinotify': 'dev-python/pyinotify',
},
'Arch': {
'salt_master': 'salt',
'salt_minion': 'salt',
'salt_syndic': 'salt',
'salt_cloud': 'salt',
'salt_api': 'salt',
'salt_ssh': 'salt',
'python_git': 'python2-gitpython',
'pygit2': 'python2-pygit2',
'libgit2': 'libgit2',
'pyinotify': 'python2-pyinotify',
},
'Alpine': {
'salt_master': 'salt-master',
'salt_minion': 'salt-minion',
'salt_syndic': 'salt-syndic',
'salt_cloud': 'salt-cloud',
'salt_api': 'salt-api',
'salt_ssh': 'salt-ssh',
'pygit2': 'py2-pygit2',
'libgit2': 'libgit2',
},
'FreeBSD': {
'salt_master': 'py27-salt',
'salt_minion': 'py27-salt',
'salt_syndic': 'py27-salt',
'salt_cloud': 'py27-salt',
'salt_api': 'py27-salt',
'salt_ssh': 'py27-salt',
'python_git': 'py27-GitPython',
'pygit2': 'py27-pygit2',
'config_path': '/usr/local/etc/salt',
'minion_service': 'salt_minion',
'master_service': 'salt_master',
'api_service': 'salt_api',
'syndic_service': 'salt_syndic',
},
'OpenBSD': {
'salt_master': 'salt',
'salt_minion': 'salt',
'salt_syndic': 'salt',
'salt_cloud': 'salt',
'salt_api': 'salt',
'salt_ssh': 'salt',
'config_path': '/etc/salt',
'minion_service': 'salt_minion',
'master_service': 'salt_master',
'python_git': 'py-GitPython',
},
'Windows': {
'salt_minion': 'salt-minion',
'config_path': 'C:\salt\conf',
'minion_service': 'salt-minion',
},
'MacOS': {
'salt_minion': 'com.saltstack.salt',
'salt_minion_pkg_source': '',
'salt_minion_pkg_hash': '',
'config_path': '/private/etc/salt',
'minion_service': 'com.saltstack.salt.minion',
},
}, merge=salt['grains.filter_by']({
'Ubuntu': {
'pkgrepo': 'deb http://repo.saltstack.com/apt/' +
salt['grains.get']('os')|lower + '/' + osrelease + '/amd64/' + salt_release + ' ' + salt['grains.get']('oscodename') + ' main',
'key_url': 'https://repo.saltstack.com/apt/' + salt['grains.get']('os')|lower + '/' + osrelease + '/amd64/' + salt_release + '/SALTSTACK-GPG-KEY.pub',
'pygit2': 'python-pygit2',
'gitfs': {
'pygit2': {
'install_from_source': False,
'git': {
'require_state': False,
'install_from_package': None,
},
},
},
},
'Raspbian': {
'pkgrepo': 'deb http://repo.saltstack.com/apt/' +
salt['grains.get']('os_family')|lower + '/' + salt['grains.get']('osmajorrelease', osrelease)|string + '/armhf/' + salt_release + ' ' + salt['grains.get']('oscodename') + ' main',
'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',
},
'SmartOS': {
'salt_master': 'salt',
'salt_minion': 'salt',
'salt_syndic': 'salt',
'salt_cloud': 'salt',
'salt_api': 'salt',
'salt_ssh': 'salt',
'minion_service': 'salt:minion',
'master_service': 'salt:master',
'api_service': 'salt:api',
'python_dulwich': 'py27-dulwich',
'gitfs': {
'dulwich': {
'install_from_source': False,
}
},
'config_path': '/opt/local/etc/salt',
'master': {
'gitfs_provider': 'dulwich'
},
}
}, grain='os', merge=salt['pillar.get']('salt:lookup')))
%}

{## Merge the flavor_map to the default settings ##}
{% do deep_merge(default_settings.salt,os_family_map) %}
{# merge the osmap #}
{% set osmap = salt['grains.filter_by'](osmap, grain='os') or{} %}
{% do salt['defaults.merge'](defaults['salt'], osmap) %}

{## Merge in salt pillar ##}
{% set salt_settings = salt['pillar.get'](
'salt',
default=default_settings.salt,
merge=True)
%}
{% set salt_settings = salt['pillar.get']('salt', default=defaults['salt'], merge=True) %}

{## Merge in salt_formulas pillar ##}
{% set formulas_settings = salt['pillar.get'](
'salt_formulas',
default=default_settings.salt_formulas,
merge=True)
%}
{% set formulas_settings = salt['pillar.get']('salt_formulas',default=defaults['salt_formulas'], merge=True) %}
123 changes: 123 additions & 0 deletions salt/osfamilymap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml

{% set osrelease = salt['grains.get']('osrelease') %}
{% set salt_release = salt['pillar.get']('salt:release', 'latest') %}
{% if salt_release.split('.')|length >= 3 %}
{% set salt_release = 'archive/' ~ salt_release %}
{% endif %}
{% set os_lower = salt['grains.get']('os')|lower %}
{% set osmajorrelease = salt['grains.get']('osmajorrelease', osrelease)|string %}
{% set oscodename = salt['grains.get']('oscodename') %}

Debian:
pkgrepo: 'deb http://repo.saltstack.com/apt/{{ os_lower }}/{{ osmajorrelease }}/amd64/{{ salt_release }} {{ oscodename }} main'
key_url: 'https://repo.saltstack.com/apt/{{ os_lower }}/{{ osmajorrelease }}/amd64/{{ salt_release }}/SALTSTACK-GPG-KEY.pub'
libgit2: libgit2-22
pyinotify: python-pyinotify
gitfs:
pygit2:
install_from_source: True
version: 0.22.1
git:
require_state: False
install_from_package: git
libgit2:
install_from_source: False

RedHat:
pkgrepo: 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/{{ salt_release }}'
key_url: 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/{{ salt_release }}/SALTSTACK-GPG-KEY.pub'
pygit2: python-pygit2
python_git: GitPython
gitfs:
gitpython:
install_from_source: False
pygit2:
install_from_source: False
git:
require_state: False
install_from_package: git
master:
gitfs_provider: pygit2

Suse:
pygit2: python-pygit2
pyinotify: python-pyinotify
gitfs:
pygit2:
install_from_source: False
git:
require_state: False
install_from_package: git
master:
gitfs_provider: pygit2

Gentoo:
salt_master: app-admin/salt
salt_minion: app-admin/salt
salt_syndic: app-admin/salt
salt_api: app-admin/salt
salt_cloud: app-admin/salt
pyinotify: dev-python/pyinotify

Arch:
salt_master: salt
salt_minion: salt
salt_syndic: salt
salt_cloud: salt
salt_api: salt
salt_ssh: salt
python_git: python2-gitpython
pygit2: python2-pygit2
libgit2: libgit2
pyinotify: python2-pyinotify

Alpine:
salt-master: salt-master
salt_minion: salt-minion
salt_syndic: salt-syndic
salt_cloud: salt-cloud
salt_api: salt-api
salt_ssh: salt-ssh
pygit2: py2-pygit2
libgit2: libgit2

FreeBSD:
salt_master: py27-salt
salt_minion: py27-salt
salt_syndic: py27-salt
salt_cloud: py27-salt
salt_api: py27-salt
salt_ssh: py27-salt
python_git: py27-GitPython
pygit2: py27-pygit2
config_path: /usr/local/etc/salt
minion_service: salt_minion
master_service: salt_master
api_service: salt_api
syndic_service: salt_syndic

OpenBSD:
salt_master: salt
salt_minion: salt
salt_syndic: salt
salt_cloud: salt
salt_api: salt
salt_ssh: salt
config_path: /etc/salt
minion_service: salt_minion
master_service: salt_master
python_git: py-GitPython

Windows:
salt_minion: salt-minion
config_path: 'C:\salt\conf'
minion_service: salt-minion

MacOS:
salt_minion: com.saltstack.salt
salt_minion_pkg_source: ''
salt_minion_pkg_hash: ''
config_path: /private/etc/salt
minion_service: com.saltstack.salt.minion
Loading