From cdd85c68c3f7f732b94552d7954623e18474f031 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 26 Aug 2019 00:32:51 +0200 Subject: [PATCH] refactor(pillar): sync map.jinja with template-formula --- timezone/defaults.yaml | 12 ++++++-- timezone/init.sls | 25 +++++++++-------- timezone/map.jinja | 58 +++++++++++++++++++++++++++++++-------- timezone/osarchmap.yaml | 35 +++++++++++++++++++++++ timezone/osfamilymap.yaml | 23 ++++++++++++++-- timezone/osfingermap.yaml | 13 +++++++++ timezone/osmap.yaml | 13 +++++++++ 7 files changed, 149 insertions(+), 30 deletions(-) create mode 100644 timezone/osarchmap.yaml create mode 100644 timezone/osfingermap.yaml create mode 100644 timezone/osmap.yaml diff --git a/timezone/defaults.yaml b/timezone/defaults.yaml index e62efb4..2574215 100644 --- a/timezone/defaults.yaml +++ b/timezone/defaults.yaml @@ -1,4 +1,10 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml --- -path_localtime: /etc/localtime -path_zoneinfo: /usr/share/zoneinfo/ -pkgname: tzdata +timezone: + name: Europe/Berlin + utc: true + path_localtime: /etc/localtime + path_zoneinfo: /usr/share/zoneinfo/ + pkg: + name: tzdata diff --git a/timezone/init.sls b/timezone/init.sls index e21bb5d..3372550 100644 --- a/timezone/init.sls +++ b/timezone/init.sls @@ -1,26 +1,27 @@ -# This state configures the timezone. +# -*- coding: utf-8 -*- +# vim: ft=sls -{%- set timezone = salt['pillar.get']('timezone:name', 'Europe/Berlin') %} -{%- set utc = salt['pillar.get']('timezone:utc', True) %} -{% from "timezone/map.jinja" import confmap with context %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import timezone with context %} timezone_setting: timezone.system: - - name: {{ timezone }} - - utc: {{ utc }} + - name: {{ timezone.name }} + - utc: {{ timezone.utc }} - {%- if grains.os not in ('MacOS', 'Windows') %} +{%- if grains.os not in ('MacOS', 'Windows') %} timezone_packages: pkg.installed: - - name: {{ confmap.pkgname }} + - name: {{ timezone.pkg.name }} timezone_symlink: file.symlink: - - name: {{ confmap.path_localtime }} - - target: {{ confmap.path_zoneinfo }}{{ timezone }} + - name: {{ timezone.path_localtime }} + - target: {{ timezone.path_zoneinfo }}{{ timezone.name }} - force: true - require: - - pkg: {{ confmap.pkgname }} + - pkg: {{ timezone.pkg.name }} - {%- endif %} +{%- endif %} diff --git a/timezone/map.jinja b/timezone/map.jinja index d4c9da8..bc401d0 100644 --- a/timezone/map.jinja +++ b/timezone/map.jinja @@ -1,15 +1,49 @@ -{% import_yaml "timezone/defaults.yaml" as defaults %} -{% import_yaml "timezone/osfamilymap.yaml" as osfamilymap %} +# -*- coding: utf-8 -*- +# vim: ft=jinja -{% set osfam = salt['grains.filter_by']( - osfamilymap, - grain='os_family' - ) or {} %} +{#- 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 %} -{% do salt['defaults.merge'](defaults, osfam) %} +{#- Retrieve the config dict only once #} +{%- set _config = salt['config.get'](tplroot, default={}) %} -{%- set confmap = salt['pillar.get']( - 'timezone:lookup', - default=defaults, - merge=True, - ) %} +{%- 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 timezone = config %} diff --git a/timezone/osarchmap.yaml b/timezone/osarchmap.yaml new file mode 100644 index 0000000..ab3bc1f --- /dev/null +++ b/timezone/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/timezone/osfamilymap.yaml b/timezone/osfamilymap.yaml index 424a2f8..96a9c0f 100644 --- a/timezone/osfamilymap.yaml +++ b/timezone/osfamilymap.yaml @@ -1,8 +1,25 @@ +# -*- 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: {} --- Suse: - pkgname: timezone + pkg: + name: timezone + FreeBSD: - pkgname: zoneinfo + pkg: + name: zoneinfo + Gentoo: - pkgname: sys-libs/timezone-data + pkg: + name: sys-libs/timezone-data + MacOS: {} diff --git a/timezone/osfingermap.yaml b/timezone/osfingermap.yaml new file mode 100644 index 0000000..221bedf --- /dev/null +++ b/timezone/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/timezone/osmap.yaml b/timezone/osmap.yaml new file mode 100644 index 0000000..2ec94b4 --- /dev/null +++ b/timezone/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: {}