refactor(pillar): sync map.jinja with template-formula

This commit is contained in:
Nicolas Rodriguez 2019-08-26 00:32:51 +02:00
parent dbc811f1dc
commit cdd85c68c3
7 changed files with 149 additions and 30 deletions

View File

@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
--- ---
path_localtime: /etc/localtime timezone:
path_zoneinfo: /usr/share/zoneinfo/ name: Europe/Berlin
pkgname: tzdata utc: true
path_localtime: /etc/localtime
path_zoneinfo: /usr/share/zoneinfo/
pkg:
name: tzdata

View File

@ -1,26 +1,27 @@
# This state configures the timezone. # -*- coding: utf-8 -*-
# vim: ft=sls
{%- set timezone = salt['pillar.get']('timezone:name', 'Europe/Berlin') %} {#- Get the `tplroot` from `tpldir` #}
{%- set utc = salt['pillar.get']('timezone:utc', True) %} {%- set tplroot = tpldir.split('/')[0] %}
{% from "timezone/map.jinja" import confmap with context %} {%- from tplroot ~ "/map.jinja" import timezone with context %}
timezone_setting: timezone_setting:
timezone.system: timezone.system:
- name: {{ timezone }} - name: {{ timezone.name }}
- utc: {{ utc }} - utc: {{ timezone.utc }}
{%- if grains.os not in ('MacOS', 'Windows') %} {%- if grains.os not in ('MacOS', 'Windows') %}
timezone_packages: timezone_packages:
pkg.installed: pkg.installed:
- name: {{ confmap.pkgname }} - name: {{ timezone.pkg.name }}
timezone_symlink: timezone_symlink:
file.symlink: file.symlink:
- name: {{ confmap.path_localtime }} - name: {{ timezone.path_localtime }}
- target: {{ confmap.path_zoneinfo }}{{ timezone }} - target: {{ timezone.path_zoneinfo }}{{ timezone.name }}
- force: true - force: true
- require: - require:
- pkg: {{ confmap.pkgname }} - pkg: {{ timezone.pkg.name }}
{%- endif %} {%- endif %}

View File

@ -1,15 +1,49 @@
{% import_yaml "timezone/defaults.yaml" as defaults %} # -*- coding: utf-8 -*-
{% import_yaml "timezone/osfamilymap.yaml" as osfamilymap %} # vim: ft=jinja
{% set osfam = salt['grains.filter_by']( {#- 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, osfamilymap,
grain='os_family' grain='os_family',
) or {} %} merge=salt['grains.filter_by'](
osmap,
grain='os',
merge=salt['grains.filter_by'](
osfingermap,
grain='osfinger',
merge=salt['grains.filter_by'](
_config,
default='lookup'
)
)
)
)
)
)
%}
{% do salt['defaults.merge'](defaults, osfam) %} {%- set config = salt['grains.filter_by'](
{'defaults': defaults},
default='defaults',
merge=_config
)
%}
{%- set confmap = salt['pillar.get']( {%- set timezone = config %}
'timezone:lookup',
default=defaults,
merge=True,
) %}

35
timezone/osarchmap.yaml Normal file
View File

@ -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

View File

@ -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: Suse:
pkgname: timezone pkg:
name: timezone
FreeBSD: FreeBSD:
pkgname: zoneinfo pkg:
name: zoneinfo
Gentoo: Gentoo:
pkgname: sys-libs/timezone-data pkg:
name: sys-libs/timezone-data
MacOS: {} MacOS: {}

13
timezone/osfingermap.yaml Normal file
View File

@ -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
timezone/osmap.yaml Normal file
View File

@ -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: {}