Skip to content

Commit

Permalink
feat(maj.jinja): authorise literal file path in “map.jinja:sources”
Browse files Browse the repository at this point in the history
This mimic the behavior of “libtofs.jinja”.
  • Loading branch information
baby-gnu committed Feb 15, 2020
1 parent f06238d commit baa44d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions TEMPLATE/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@

{%- for map_source in map_sources %}
{# Lookup the grain/pillar/... #}
{# Fallback to use the source name as a direct filename #}
{%- set map_values = salt['config.get'](map_source, []) %}

{# Mangle `map_source` to use it as literal path #}
{%- if map_values|length == 0 %}
{%- set map_source_parts = map_source.split('/') %}
{%- set map_source = map_source_parts[0:-1] | join('/') %}
{%- set map_values = map_source_parts[-1].rstrip('.yaml') %}
{%- endif %}

{# Some configuration return list #}
{%- if map_values is string %}
{%- set map_values = [map_values] %}
{%- endif %}
Expand Down
8 changes: 7 additions & 1 deletion TEMPLATE/parameters/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ subcomponent:
# Just here for testing
added_in_defaults: defaults_value
winner: defaults
# Configure map.jinja to load formula parameters values
# Configure map.jinja to load formula parameters values and merge them
# in the order from most generic (first) to most specific (last).
# Each source can define the merging `strategy` which default to the
# `smart` strategy of `salt.slsutil.merge`.
# Note: Any value not evaluated by `config.get` will be used literally.
# This can be used to set custom paths, as many levels deep as required.
map.jinja:
sources:
- osarch
- os_family
- os
- osfinger
- roles
- any/path/can/be/used/here.yaml

0 comments on commit baa44d9

Please sign in to comment.