|
2 | 2 | lookup=None,
|
3 | 3 | default_files_switch=['id', 'os_family'],
|
4 | 4 | indent_width=6,
|
5 |
| - v1_path_prefix='') %} |
| 5 | + use_subpath=False) %} |
6 | 6 | {#-
|
7 | 7 | Returns a valid value for the "source" parameter of a "file.managed"
|
8 | 8 | state function. This makes easier the usage of the Template Override and
|
|
17 | 17 | use as selector switch of the directories under
|
18 | 18 | "<path_prefix>/files"
|
19 | 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 |
| 20 | + * use_subpath: defaults to `False` but if set, lookup the source file |
| 21 | + recursively from the current state directory up to `tplroot` |
22 | 22 |
|
23 | 23 | Example (based on a `tplroot` of `xxx`):
|
24 | 24 |
|
|
64 | 64 | {%- set src_files = src_files + source_files %}
|
65 | 65 | {#- Only add to [''] when supporting older TOFS implementations #}
|
66 | 66 | {%- set path_prefix_exts = [''] %}
|
67 |
| - {%- if v1_path_prefix != '' %} |
68 |
| - {%- do path_prefix_exts.append(v1_path_prefix) %} |
| 67 | + {%- if use_subpath and tplroot != tpldir %} |
| 68 | + {#- Walk directory tree to find {{ files_dir }} #} |
| 69 | + {%- set subpath_parts = tpldir.lstrip(tplroot).lstrip('/').split('/') %} |
| 70 | + {%- for path in subpath_parts %} |
| 71 | + {%- set subpath = subpath_parts[0:loop.index] | join('/') %} |
| 72 | + {%- do path_prefix_exts.append('/' ~ subpath) %} |
| 73 | + {%- endfor %} |
69 | 74 | {%- endif %}
|
70 |
| - {%- for path_prefix_ext in path_prefix_exts %} |
| 75 | + {%- for path_prefix_ext in path_prefix_exts|reverse %} |
71 | 76 | {%- set path_prefix_inc_ext = path_prefix ~ path_prefix_ext %}
|
72 | 77 | {#- For older TOFS implementation, use `files_switch` from the config #}
|
73 | 78 | {#- Use the default, new method otherwise #}
|
|
0 commit comments