From a98b77723a1423365da963e3368e891bec9d2bce Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sun, 24 Mar 2019 03:41:46 +0000 Subject: [PATCH] refactor(tofs): make `files_switch` macro fully portable * Introduce `v1_path_prefix` parameter --- template/libtofs.jinja | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/template/libtofs.jinja b/template/libtofs.jinja index 018e63d6..134496e9 100644 --- a/template/libtofs.jinja +++ b/template/libtofs.jinja @@ -1,7 +1,8 @@ {%- macro files_switch(source_files, lookup=None, default_files_switch=['id', 'os_family'], - indent_width=6) %} + indent_width=6, + v1_path_prefix='') %} {#- Returns a valid value for the "source" parameter of a "file.managed" state function. This makes easier the usage of the Template Override and @@ -16,6 +17,8 @@ use as selector switch of the directories under "/files" * indent_witdh: indentation of the result value to conform to YAML + * v1_path_prefix: (deprecated) only used for injecting a path prefix into + the source, to support older TOFS pillars Example (based on a `tplroot` of `xxx`): @@ -58,7 +61,11 @@ source_files ) %} {#- Only add to [''] when supporting older TOFS implementations #} - {%- for path_prefix_ext in [''] %} + {%- set path_prefix_exts = [''] %} + {%- if v1_path_prefix != '' %} + {%- do path_prefix_exts.append(v1_path_prefix) %} + {%- endif %} + {%- for path_prefix_ext in path_prefix_exts %} {%- set path_prefix_inc_ext = path_prefix ~ path_prefix_ext %} {#- For older TOFS implementation, use `files_switch` from the pillar #} {#- Use the default, new method otherwise #}