|
1 | 1 | {%- macro files_switch(source_files, |
2 | 2 | lookup=None, |
3 | 3 | default_files_switch=['id', 'os_family'], |
4 | | - indent_width=6) %} |
| 4 | + indent_width=6, |
| 5 | + v1_path_prefix='') %} |
5 | 6 | {#- |
6 | 7 | Returns a valid value for the "source" parameter of a "file.managed" |
7 | 8 | state function. This makes easier the usage of the Template Override and |
|
11 | 12 | * source_files: ordered list of files to look for |
12 | 13 | * lookup: key under '<tplroot>:tofs:source_files' to override |
13 | 14 | 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) |
15 | 16 | '<tplroot>:tofs:files_switch' this is the ordered list of grains to |
16 | 17 | use as selector switch of the directories under |
17 | 18 | "<path_prefix>/files" |
18 | 19 | * 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 |
19 | 22 |
|
20 | 23 | Example (based on a `tplroot` of `xxx`): |
21 | 24 |
|
|
52 | 55 | tplroot ~ ':tofs:files_switch', |
53 | 56 | default_files_switch |
54 | 57 | ) %} |
55 | | - {#- Lookup files or fallback to source_files parameter #} |
| 58 | + {#- Lookup source_files (v2), files (v1), or fallback to source_files parameter #} |
56 | 59 | {%- set src_files = salt['config.get']( |
57 | 60 | tplroot ~ ':tofs:source_files:' ~ lookup, |
58 | | - source_files |
| 61 | + salt['config.get']( |
| 62 | + tplroot ~ ':tofs:files:' ~ lookup, |
| 63 | + source_files |
| 64 | + ) |
59 | 65 | ) %} |
60 | 66 | {#- 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 %} |
62 | 72 | {%- 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 #} |
64 | 74 | {#- Use the default, new method otherwise #} |
65 | | - {%- set fsl = salt['pillar.get']( |
| 75 | + {%- set fsl = salt['config.get']( |
66 | 76 | tplroot ~ path_prefix_ext|replace('/', ':') ~ ':files_switch', |
67 | 77 | files_switch_list |
68 | 78 | ) %} |
|
0 commit comments