Skip to content

Commit 0d45135

Browse files
authored
Merge pull request #83 from myii/refactor/libtofs
refactor(tofs): update with latest changes inc. 100% portable `libtofs.jinja`
2 parents 709d6a2 + 3e62d7b commit 0d45135

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

template/libtofs.jinja

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{%- macro files_switch(source_files,
22
lookup=None,
33
default_files_switch=['id', 'os_family'],
4-
indent_width=6) %}
4+
indent_width=6,
5+
v1_path_prefix='') %}
56
{#-
67
Returns a valid value for the "source" parameter of a "file.managed"
78
state function. This makes easier the usage of the Template Override and
@@ -11,11 +12,13 @@
1112
* source_files: ordered list of files to look for
1213
* lookup: key under '<tplroot>:tofs:source_files' to override
1314
list of source files
14-
* default_files_switch: if there's no pillar
15+
* default_files_switch: if there's no config (e.g. pillar)
1516
'<tplroot>:tofs:files_switch' this is the ordered list of grains to
1617
use as selector switch of the directories under
1718
"<path_prefix>/files"
1819
* indent_witdh: indentation of the result value to conform to YAML
20+
* v1_path_prefix: (deprecated) only used for injecting a path prefix into
21+
the source, to support older TOFS configs
1922
2023
Example (based on a `tplroot` of `xxx`):
2124
@@ -52,17 +55,24 @@
5255
tplroot ~ ':tofs:files_switch',
5356
default_files_switch
5457
) %}
55-
{#- Lookup files or fallback to source_files parameter #}
58+
{#- Lookup source_files (v2), files (v1), or fallback to source_files parameter #}
5659
{%- set src_files = salt['config.get'](
5760
tplroot ~ ':tofs:source_files:' ~ lookup,
58-
source_files
61+
salt['config.get'](
62+
tplroot ~ ':tofs:files:' ~ lookup,
63+
source_files
64+
)
5965
) %}
6066
{#- Only add to [''] when supporting older TOFS implementations #}
61-
{%- for path_prefix_ext in [''] %}
67+
{%- set path_prefix_exts = [''] %}
68+
{%- if v1_path_prefix != '' %}
69+
{%- do path_prefix_exts.append(v1_path_prefix) %}
70+
{%- endif %}
71+
{%- for path_prefix_ext in path_prefix_exts %}
6272
{%- set path_prefix_inc_ext = path_prefix ~ path_prefix_ext %}
63-
{#- For older TOFS implementation, use `files_switch` from the pillar #}
73+
{#- For older TOFS implementation, use `files_switch` from the config #}
6474
{#- Use the default, new method otherwise #}
65-
{%- set fsl = salt['pillar.get'](
75+
{%- set fsl = salt['config.get'](
6676
tplroot ~ path_prefix_ext|replace('/', ':') ~ ':files_switch',
6777
files_switch_list
6878
) %}

0 commit comments

Comments
 (0)