Skip to content

Commit

Permalink
Merge pull request #11 from n-rodriguez/wip/map
Browse files Browse the repository at this point in the history
feat(map): sync map.jinja with template-formula
  • Loading branch information
aboe76 authored Sep 25, 2019
2 parents a50c209 + 5ddd1c9 commit fabe0b7
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 17 deletions.
8 changes: 4 additions & 4 deletions exim/config/file.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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') %}
Expand All @@ -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 }}'
Expand All @@ -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 %}
Expand Down
4 changes: 4 additions & 0 deletions exim/defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
exim: {}
58 changes: 49 additions & 9 deletions exim/map.jinja
Original file line number Diff line number Diff line change
@@ -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 %}
35 changes: 35 additions & 0 deletions exim/osarchmap.yaml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions exim/osfamilymap.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions exim/osfingermap.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
13 changes: 13 additions & 0 deletions exim/osmap.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
4 changes: 2 additions & 2 deletions exim/package/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 2 additions & 2 deletions exim/service/running.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit fabe0b7

Please sign in to comment.