Skip to content

Commit

Permalink
refactor(pillar): sync map.jinja with template-formula
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Aug 25, 2019
1 parent e0c92a3 commit 9fe13b4
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 22 deletions.
9 changes: 7 additions & 2 deletions locale/init.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Installs and configures system locales
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import locale with context %}
{% from "locale/map.jinja" import locale with context %}
# Installs and configures system locales
{% if locale.pkgs is iterable %}
locale_pkgs:
Expand Down
63 changes: 43 additions & 20 deletions locale/map.jinja
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
{% import_yaml 'locale/defaults.yaml' as default_settings %}
# -*- coding: utf-8 -*-
# vim: ft=jinja

{% set os_family_map = salt['grains.filter_by']({
'Debian': {
'pkgs': ['locales'],
},
'Arch': {
'pkgs': ['glibc'],
},
'Suse': {
'pkgs': ['glibc-locale'],
},
'RedHat': {
'pkgs': ['glibc-common'],
},
{#- 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 %}

}, grain='os_family', merge=salt['pillar.get']('locale:lookup')) %}
{#- Retrieve the config dict only once #}
{%- set _config = salt['config.get'](tplroot, default={}) %}

{% do default_settings.locale.update(os_family_map) %}
{%- 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 locale = salt['pillar.get'](
'locale',
default=default_settings.locale,
merge=True
{%- set config = salt['grains.filter_by'](
{'defaults': defaults},
default='defaults',
merge=_config
)
%}

{%- set locale = config %}
35 changes: 35 additions & 0 deletions locale/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
27 changes: 27 additions & 0 deletions locale/osfamilymap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- 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: {}
---
Debian:
pkgs:
- locales

RedHat:
pkgs:
- glibc-common

Suse:
pkgs:
- glibc-locale

Arch:
pkgs:
- glibc
13 changes: 13 additions & 0 deletions locale/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 locale/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: {}

0 comments on commit 9fe13b4

Please sign in to comment.