-
Notifications
You must be signed in to change notification settings - Fork 85
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
feat(map): update to v5 map.jinja #225
feat(map): update to v5 map.jinja #225
Conversation
Update `_mapdata` reference files to include the `map.jinja` configuration sources.
@baby-gnu Some initial feedback, just diff-ing across the three formulas. This PR and --- .../openssh-formula/openssh/libmapstack.jinja
+++ .../template-formula/TEMPLATE/libmapstack.jinja
@@ -95,8 +95,10 @@
{%- set stack = defaults | default({"values": {} }, boolean=True) %}
{#- Build configuration file names based on matchers #}
+{%- set config_get_strategy = salt["config.get"](tplroot ~ ":strategy", None) %}
{%- set matchers = parse_matchers(
matchers,
+ config_get_strategy=config_get_strategy,
log_prefix=log_prefix
)
| load_yaml %}
@@ -194,6 +196,19 @@
{%- set yaml_names = [yaml_names] %}
{%- endif %}
+{#- Try to load a `.yaml.jinja` file for each `.yaml` file #}
+{%- set all_yaml_names = [] %}
+{%- for name in yaml_names %}
+{%- set extension = name.rpartition(".")[2] %}
+{%- if extension not in ["yaml", "jinja"] %}
+{%- do all_yaml_names.extend([name ~ ".yaml", name ~ ".yaml.jinja"]) %}
+{%- elif extension == "yaml" %}
+{%- do all_yaml_names.extend([name, name ~ ".jinja"]) %}
+{%- else %}
+{%- do all_yaml_names.append(name) %}
+{%- endif %}
+{%- endfor %}
+
{#- `yaml_dirname` can be an empty string with literal path like `myconf.yaml` #}
{%- set yaml_dir = [
param_dir,
@@ -202,15 +217,10 @@
| select
| join("/") %}
-{%- for yaml_name in yaml_names %}
-{#- Make sure to have a `.yaml` extension #}
-{#- Use `.rpartition` to strip last `.yaml` in `dir.yaml/file.yaml` #}
+{%- for yaml_name in all_yaml_names %}
{%- set yaml_filename = [
yaml_dir.rstrip("/"),
- yaml_name.rpartition(".yaml")
- | reject("equalto", ".yaml")
- | join
- ~ ".yaml"
+ yaml_name
]
| select
| join("/") %}
@@ -228,7 +238,7 @@
{%- do salt["log.debug"](
log_prefix
~ "loaded configuration values from "
- ~ yaml_name
+ ~ yaml_filename
~ ":\n"
~ yaml_values
| yaml(False)
@@ -271,7 +281,7 @@
{%- do salt["log.debug"](
log_prefix
~ "merged configuration values from "
- ~ yaml_name
+ ~ yaml_filename
~ ", merge: strategy='"
~ strategy
~ "', merge_lists='" --- .../openssh-formula/openssh/map.jinja
+++ .../template-formula/TEMPLATE/map.jinja
@@ -38,6 +38,7 @@
{#- Load formula parameters values #}
{%- set _formula_matchers = ["defaults.yaml"] + map_sources %}
+
{%- set _formula_settings = mapstack(
matchers=_formula_matchers,
dirs=[formula_param_dir],
@@ -59,3 +60,7 @@
{%- do salt["log.debug"]("map.jinja: save parameters in variable 'mapdata'") %}
{%- set mapdata = _formula_settings["values"] %}
+
+{#- Per formula post-processing of `mapdata` if it exists #}
+{%- do salt["log.debug"]("map.jinja: post-processing of 'mapdata'") %}
+{%- include tplroot ~ "/post-map.jinja" ignore missing %} |
The v5 `map.jinja` is a generic and configurable system to load configuration values, exposed as the `mapdata` variable, from different places: - YAML files and templates from the fileserver for non-secret data - pillars or SDB are preferred for secret data - grains or `config.get` The `map.jinja` optional sources are configured with compound targeting like syntax `[<TYPE>[:<OPTION>[:<DELIMITER>]]@]<KEY>` with the following default ordered sources: - `Y:G@osarch`: YAML file and Jinja template named after `osarch` grain - `Y:G@os_family`: YAML file and Jinja template named after `os_family` grain - `Y:G@os` YAML file and Jinja template named after `os` grain - `Y:G@osfinger` YAML file and Jinja template named after `osfinger` grain - `C@{{ tplroot ~ ':lookup' }}`: dict retrieved with `salt["config.get"]` - `C@{{ tplroot }}`: dict retrieved with `salt["config.get"]` - `Y:G@id`: YAML file and Jinja template named after `osarch` grain This is done by two new libraries: - `libmatchers.jinja` provides the `parse_matchers` macro to parse strings looking like compound matchers, for example `Y:G@osarch` - `libmapstack.jinja` provides the `mapstack` macro to load configuration from different sources described by matchers Post-processing of `mapdata` variable can be done in a `parameters/post-map.jinja`. The v5 `map.jinja` is documented in `docs/map.jinja.rst`. BREAKING CHANGE: `map.jinja` now exports a generic `mapdata` variable BREAKING CHANGE: The per grain parameter values are now under `TEMPLATE/parameters/`
97700ca
to
42e1932
Compare
@myii yes, the I push a fixed commit because I forgot to delete the old |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@baby-gnu Lovely! Ready for merge in my opinion but let's give @saltstack-formulas/wg a bit of time to review.
Thanks @myii. This time will give me some time for the next move ;-) |
🎉 This PR is included in version 5.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
PR progress checklist (to be filled in by reviewers)
What type of PR is this?
Primary type
[build]
Changes related to the build system[chore]
Changes to the build process or auxiliary tools and libraries such as documentation generation[ci]
Changes to the continuous integration configuration[feat]
A new feature[fix]
A bug fix[perf]
A code change that improves performance[refactor]
A code change that neither fixes a bug nor adds a feature[revert]
A change used to revert a previous commit[style]
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)Secondary type
[docs]
Documentation changes[test]
Adding missing or correcting existing testsDoes this PR introduce a
BREAKING CHANGE
?Yes.
BREAKING CHANGE:
map.jinja
now exports a genericmapdata
variableBREAKING CHANGE: The per grain parameter values are now under
TEMPLATE/parameters/
Related issues and/or pull requests
map.jinja
openvpn-formula#134Describe the changes you're proposing
feat(map): update to v5
map.jinja
The v5
map.jinja
is a generic and configurable system to load configuration values, exposed as themapdata
variable, from different places:config.get
The
map.jinja
optional sources are configured with compound targeting like syntax[<TYPE>[:<OPTION>[:<DELIMITER>]]@]<KEY>
with the following default ordered sources:Y:G@osarch
: YAML file and Jinja template named afterosarch
grainY:G@os_family
: YAML file and Jinja template named afteros_family
grainY:G@os
YAML file and Jinja template named afteros
grainY:G@osfinger
YAML file and Jinja template named afterosfinger
grainC@{{ tplroot ~ ':lookup' }}
: dict retrieved withsalt["config.get"]
C@{{ tplroot }}
: dict retrieved withsalt["config.get"]
Y:G@id
: YAML file and Jinja template named afterosarch
grainThis is done by two new libraries:
libmatchers.jinja
provides theparse_matchers
macro to parse strings looking like compound matchers, for exampleY:G@osarch
libmapstack.jinja
provides themapstack
macro to load configuration from different sources described by matchersPost-processing of
mapdata
variable can be done in aparameters/post-map.jinja
.The v5
map.jinja
is documented indocs/map.jinja.rst
.Pillar / config required to test the proposed changes
Debug log showing how the proposed changes work
Log of the processing of map.jinja
Documentation checklist
README
(e.g.Available states
).pillar.example
.Testing checklist
state_top
).Additional context