From 7e6ad3bbfdc1e8d2fc8cf2e041c244869173c79a Mon Sep 17 00:00:00 2001 From: Mark Gomersbach Date: Mon, 15 Oct 2018 15:05:01 +0200 Subject: [PATCH] Set vars in YAML files - Add defaults YAML - Add osfamilymap YAML - Add lookup dict merge to support user overrides - Add Gentoo support --- timezone/defaults.yaml | 3 +++ timezone/map.jinja | 42 +++++++++++++-------------------------- timezone/osfamilymap.yaml | 6 ++++++ 3 files changed, 23 insertions(+), 28 deletions(-) create mode 100644 timezone/defaults.yaml create mode 100644 timezone/osfamilymap.yaml diff --git a/timezone/defaults.yaml b/timezone/defaults.yaml new file mode 100644 index 0000000..41253fd --- /dev/null +++ b/timezone/defaults.yaml @@ -0,0 +1,3 @@ +path_localtime: /etc/localtime +path_zoneinfo: /usr/share/zoneinfo/ +pkgname: tzdata \ No newline at end of file diff --git a/timezone/map.jinja b/timezone/map.jinja index d17e545..efdfecd 100644 --- a/timezone/map.jinja +++ b/timezone/map.jinja @@ -1,29 +1,15 @@ -{% set map = { - 'Debian': { - 'path_localtime': '/etc/localtime', - 'path_zoneinfo': '/usr/share/zoneinfo/', - 'pkgname': 'tzdata', - }, - 'RedHat': { - 'path_localtime': '/etc/localtime', - 'path_zoneinfo': '/usr/share/zoneinfo/', - 'pkgname': 'tzdata', - }, - 'Suse': { - 'path_localtime': '/etc/localtime', - 'path_zoneinfo': '/usr/share/zoneinfo/', - 'pkgname': 'timezone', - }, - 'Arch': { - 'path_localtime': '/etc/localtime', - 'path_zoneinfo': '/usr/share/zoneinfo/', - 'pkgname': 'tzdata', - }, - 'FreeBSD': { - 'path_localtime': '/etc/localtime', - 'path_zoneinfo': '/usr/share/zoneinfo/', - 'pkgname': 'zoneinfo', - }, -} %} +{% import_yaml "timezone/defaults.yaml" as defaults %} +{% import_yaml "timezone/osfamilymap.yaml" as osfamilymap %} -{% set confmap = map.get(grains.os_family) %} +{% set osfam = salt['grains.filter_by']( + osfamilymap, + grain='os_family' + ) or {} %} + +{% do salt['defaults.merge'](defaults, osfam) %} + +{%- set confmap = salt['pillar.get']( + 'timezone:lookup', + default=defaults, + merge=True, + ) %} \ No newline at end of file diff --git a/timezone/osfamilymap.yaml b/timezone/osfamilymap.yaml new file mode 100644 index 0000000..f0b0459 --- /dev/null +++ b/timezone/osfamilymap.yaml @@ -0,0 +1,6 @@ +Suse: + pkgname: timezone +FreeBSD: + pkgname: zoneinfo +Gentoo: + pkgname: sys-libs/timezone-data \ No newline at end of file