Skip to content

Commit

Permalink
feat(map): allow jinja processing of parameters values
Browse files Browse the repository at this point in the history
We allow the load of `.jinja` files to circumvent yamllint errors when
using Jinja in YAML files.

We load:

- `defaults.yaml.jinja` after `defaults.yaml`
- `post_map.yaml.jinja` at the end
  • Loading branch information
baby-gnu committed Jan 15, 2021
1 parent 4618fa1 commit 3759287
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
13 changes: 6 additions & 7 deletions openvpn/libmapstack.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,15 @@
| 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` #}
{#- Append a `.yaml` extension except if already present or for `.jinja` #}
{%- if yaml_name.rpartition(".")[2] not in ["yaml", "jinja"] %}
{%- set yaml_name = yaml_name ~ ".yaml" %}
{%- endif %}

{%- set yaml_filename = [
yaml_dir.rstrip("/"),
yaml_name.rpartition(".yaml")
| reject("equalto", ".yaml")
| join
~ ".yaml"
yaml_name
]
| select
| join("/") %}

{%- do salt["log.debug"](
Expand Down
9 changes: 8 additions & 1 deletion openvpn/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
) %}

{#- Load formula parameters values #}
{%- set _formula_matchers = ["defaults.yaml"] + map_sources %}
{%- set _formula_matchers =
[
"defaults.yaml",
"defaults.yaml.jinja",
]
+ map_sources
+ ["post_map.yaml.jinja"] %}

{%- set _formula_settings = mapstack(
matchers=_formula_matchers,
dirs=[formula_param_dir],
Expand Down
3 changes: 1 addition & 2 deletions openvpn/parameters/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# yamllint disable-file
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
Expand All @@ -14,7 +13,7 @@ values:
group: nobody
# None, will default to 'user'
log_user: ~
multi_services: {{ salt['grains.has_value']('systemd') }}
multi_services: false
pkgs: ['openvpn']
service: openvpn
service_function: running
Expand Down
15 changes: 15 additions & 0 deletions openvpn/parameters/defaults.yaml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{#- -*- coding: utf-8 -*- #}
{#- vim: ft=jinja #}
{#-
Setup variables after loading `defaults.yaml`.
This jinja2 file must return a valid `map.jinja` YAML which will
be merged into `defaults.yaml`.
If you do not need to provide calculated defaults, you can remove
this file or provide at least an empty dict, e.g. values: {}
#}
---
values:
multi_services: {{ salt['grains.has_value']('systemd') }}
...

0 comments on commit 3759287

Please sign in to comment.