Skip to content

Commit

Permalink
feat(map): each YAML file loaded is followed by a .jinja one
Browse files Browse the repository at this point in the history
When `map.jinja` load a `.yaml` file, add the loading of a
`.yaml.jinja` right after to permit jinja manipulation of values.
  • Loading branch information
baby-gnu committed Jan 18, 2021
1 parent e74a757 commit 0395f7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 14 additions & 6 deletions openvpn/libmapstack.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,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,
Expand All @@ -202,12 +215,7 @@
| select
| join("/") %}

{%- for yaml_name in yaml_names %}
{#- 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 %}

{%- for yaml_name in all_yaml_names %}
{%- set yaml_filename = [
yaml_dir.rstrip("/"),
yaml_name
Expand Down
5 changes: 1 addition & 4 deletions openvpn/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@

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

Expand Down

0 comments on commit 0395f7e

Please sign in to comment.