diff --git a/exim/config/file.sls b/exim/config/file.sls index d26308d..7ae9af2 100644 --- a/exim/config/file.sls +++ b/exim/config/file.sls @@ -4,7 +4,7 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} {%- set sls_package_install = tplroot ~ '.package.install' %} -{%- from tplroot ~ "/map.jinja" import map with context %} +{%- from tplroot ~ "/map.jinja" import exim with context %} {% set use_split_config = salt['pillar.get']('exim:config:use_split_config', 'true') %} {% set configtype = salt['pillar.get']('exim:config:configtype', 'satellite') %} @@ -20,7 +20,7 @@ {% set smarthost = salt['pillar.get']('exim:config:smarthost', '') %} {% set cfilemode = salt['pillar.get']('exim:config:cfilemode', '644') %} -{{ map.config_dir }}/{{ map.config_file }}: +{{ exim.config_dir }}/{{ exim.config_file }}: file.managed: - contents: | dc_eximconfig_configtype='{{ configtype }}' @@ -38,9 +38,9 @@ CFILEMODE='{{ cfilemode }}' {% if salt['pillar.get']('exim:files') %} -{% for dir in map.sub_dirs %} +{% for dir in exim.sub_dirs %} {% for file in salt['pillar.get']('exim:files:' + dir, {}) %} -{{ map.config_dir }}/conf.d/{{ dir }}/{{ file }}: +{{ exim.config_dir }}/conf.d/{{ dir }}/{{ file }}: file.managed: - contents_pillar: exim:files:{{ dir }}:{{ file }} {% endfor %} diff --git a/exim/defaults.yaml b/exim/defaults.yaml new file mode 100644 index 0000000..5f479fc --- /dev/null +++ b/exim/defaults.yaml @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +exim: {} diff --git a/exim/map.jinja b/exim/map.jinja index 266c7c4..554a818 100644 --- a/exim/map.jinja +++ b/exim/map.jinja @@ -1,9 +1,49 @@ -{% set map = salt['grains.filter_by']({ - 'Debian': { - 'pkgs': ['exim4-daemon-light'], - 'service': 'exim4', - 'config_dir': '/etc/exim4', - 'config_file': 'update-exim4.conf.conf', - 'sub_dirs': ['main', 'acl', 'router', 'transport', 'retry', 'rewrite', 'auth'], - }, -}, grain='os', merge=salt['pillar.get']('exim:lookup'), default='Debian') %} +# -*- coding: utf-8 -*- +# vim: ft=jinja + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{#- Start imports as #} +{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %} +{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} +{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} +{%- import_yaml tplroot ~ "/osmap.yaml" as osmap %} +{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %} + +{#- Retrieve the config dict only once #} +{%- set _config = salt['config.get'](tplroot, default={}) %} + +{%- set defaults = salt['grains.filter_by']( + default_settings, + default=tplroot, + merge=salt['grains.filter_by']( + osarchmap, + grain='osarch', + merge=salt['grains.filter_by']( + osfamilymap, + grain='os_family', + merge=salt['grains.filter_by']( + osmap, + grain='os', + merge=salt['grains.filter_by']( + osfingermap, + grain='osfinger', + merge=salt['grains.filter_by']( + _config, + default='lookup' + ) + ) + ) + ) + ) + ) +%} + +{%- set config = salt['grains.filter_by']( + {'defaults': defaults}, + default='defaults', + merge=_config + ) +%} + +{%- set exim = config %} diff --git a/exim/osarchmap.yaml b/exim/osarchmap.yaml new file mode 100644 index 0000000..ab3bc1f --- /dev/null +++ b/exim/osarchmap.yaml @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +# +# Setup variables using grains['osarch'] based logic. +# You just need to add the key:values for an `osarch` that differ +# from `defaults.yaml`. +# Only add an `osarch` which is/will be supported by the formula. +# +# If you do not need to provide defaults via the `osarch` grain, +# you will need to provide at least an empty dict in this file, e.g. +# osarch: {} +--- +amd64: + arch: amd64 + +x86_64: + arch: amd64 + +386: + arch: 386 + +arm64: + arch: arm64 + +armv6l: + arch: armv6l + +armv7l: + arch: armv7l + +ppc64le: + arch: ppc64le + +s390x: + arch: s390x diff --git a/exim/osfamilymap.yaml b/exim/osfamilymap.yaml new file mode 100644 index 0000000..9319e7f --- /dev/null +++ b/exim/osfamilymap.yaml @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +# +# Setup variables using grains['os_family'] based logic. +# You just need to add the key:values for an `os_family` that differ +# from `defaults.yaml` + `osarch.yaml`. +# Only add an `os_family` which is/will be supported by the formula. +# +# If you do not need to provide defaults via the `os_family` grain, +# you will need to provide at least an empty dict in this file, e.g. +# osfamilymap: {} +--- +Debian: + pkgs: + - exim4-daemon-light + service: exim4 + config_dir: /etc/exim4 + config_file: update-exim4.conf.conf + sub_dirs: + - main + - acl + - router + - transport + - retry + - rewrite + - auth diff --git a/exim/osfingermap.yaml b/exim/osfingermap.yaml new file mode 100644 index 0000000..221bedf --- /dev/null +++ b/exim/osfingermap.yaml @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +# +# Setup variables using grains['osfinger'] based logic. +# You just need to add the key:values for an `osfinger` that differ +# from `defaults.yaml` + `osarch.yaml` + `os_family.yaml` + `osmap.yaml`. +# Only add an `osfinger` which is/will be supported by the formula. +# +# If you do not need to provide defaults via the `os_finger` grain, +# you will need to provide at least an empty dict in this file, e.g. +# osfingermap: {} +--- +osfingermap: {} diff --git a/exim/osmap.yaml b/exim/osmap.yaml new file mode 100644 index 0000000..2ec94b4 --- /dev/null +++ b/exim/osmap.yaml @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +# +# Setup variables using grains['os'] based logic. +# You just need to add the key:values for an `os` that differ +# from `defaults.yaml` + `osarch.yaml` + `os_family.yaml`. +# Only add an `os` which is/will be supported by the formula. +# +# If you do not need to provide defaults via the `os` grain, +# you will need to provide at least an empty dict in this file, e.g. +# osmap: {} +--- +osmap: {} diff --git a/exim/package/install.sls b/exim/package/install.sls index d7c237f..e6668a1 100644 --- a/exim/package/install.sls +++ b/exim/package/install.sls @@ -3,8 +3,8 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import map with context %} +{%- from tplroot ~ "/map.jinja" import exim with context %} exim/package/install: pkg.installed: - - pkgs: {{ map.pkgs | json }} + - pkgs: {{ exim.pkgs | json }} diff --git a/exim/service/running.sls b/exim/service/running.sls index 2153daa..8b08a3a 100644 --- a/exim/service/running.sls +++ b/exim/service/running.sls @@ -4,14 +4,14 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} {%- set sls_config_file = tplroot ~ '.config.file' %} -{%- from tplroot ~ "/map.jinja" import map with context %} +{%- from tplroot ~ "/map.jinja" import exim with context %} include: - {{ sls_config_file }} exim/service/running: service.running: - - name: {{ map.service }} + - name: {{ exim.service }} - enable: true - require: - sls: {{ sls_config_file }}