Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions timezone/defaults.yaml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 13 additions & 12 deletions timezone/init.sls
Original file line number Diff line number Diff line change
@@ -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 %}
58 changes: 46 additions & 12 deletions timezone/map.jinja
Original file line number Diff line number Diff line change
@@ -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 %}
35 changes: 35 additions & 0 deletions timezone/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
23 changes: 20 additions & 3 deletions timezone/osfamilymap.yaml
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions timezone/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 timezone/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: {}