Merge pull request #17 from n-rodriguez/wip/pillar

refactor(pillar): sync map.jinja with template-formula
This commit is contained in:
Niels Abspoel 2019-09-01 10:26:09 +02:00 committed by GitHub
commit 96e403ca08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
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

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') %}
{%- 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 %}

View File

@ -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'](
{#- 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'
) or {} %}
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'
)
)
)
)
)
)
%}
{% do salt['defaults.merge'](defaults, osfam) %}
{%- set config = salt['grains.filter_by'](
{'defaults': defaults},
default='defaults',
merge=_config
)
%}
{%- set confmap = salt['pillar.get'](
'timezone:lookup',
default=defaults,
merge=True,
) %}
{%- set timezone = config %}

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