|
1 | 1 | {%- macro files_switch(source_files,
|
| 2 | + lookup=None, |
2 | 3 | default_files_switch=['id', 'os_family'],
|
3 | 4 | indent_width=6) %}
|
4 | 5 | {#-
|
|
8 | 9 |
|
9 | 10 | Params:
|
10 | 11 | * source_files: ordered list of files to look for
|
| 12 | + * lookup: key under '<tplroot>:tofs:source_files' to override |
| 13 | + list of source files |
11 | 14 | * default_files_switch: if there's no pillar
|
12 | 15 | '<tplroot>:tofs:files_switch' this is the ordered list of grains to
|
13 | 16 | use as selector switch of the directories under
|
|
21 | 24 | Deploy configuration:
|
22 | 25 | file.managed:
|
23 | 26 | - name: /etc/yyy/zzz.conf
|
24 |
| - - source: {{ files_switch( |
25 |
| - salt['config.get']( |
26 |
| - tplroot ~ ':tofs:source_files:Deploy configuration', |
27 |
| - ['/etc/yyy/zzz.conf', '/etc/yyy/zzz.conf.jinja'] |
28 |
| - ) |
| 27 | + - source: {{ files_switch(['/etc/yyy/zzz.conf', '/etc/yyy/zzz.conf.jinja'], |
| 28 | + lookup='Deploy configuration' |
29 | 29 | ) }}
|
30 | 30 | - template: jinja
|
31 | 31 |
|
|
52 | 52 | tplroot ~ ':tofs:files_switch',
|
53 | 53 | default_files_switch
|
54 | 54 | ) %}
|
| 55 | + {#- Lookup files or fallback to source_files parameter #} |
| 56 | + {%- set src_files = salt['config.get']( |
| 57 | + tplroot ~ ':tofs:source_files:' ~ lookup, |
| 58 | + source_files |
| 59 | + ) %} |
55 | 60 | {#- Only add to [''] when supporting older TOFS implementations #}
|
56 | 61 | {%- for path_prefix_ext in [''] %}
|
57 | 62 | {%- set path_prefix_inc_ext = path_prefix ~ path_prefix_ext %}
|
|
66 | 71 | {%- do fsl.append('') %}
|
67 | 72 | {%- endif %}
|
68 | 73 | {%- for fs in fsl %}
|
69 |
| - {%- for source_file in source_files %} |
| 74 | + {%- for src_file in src_files %} |
70 | 75 | {%- if fs %}
|
71 | 76 | {%- set fs_dir = salt['config.get'](fs, fs) %}
|
72 | 77 | {%- else %}
|
|
76 | 81 | path_prefix_inc_ext,
|
77 | 82 | files_dir,
|
78 | 83 | fs_dir,
|
79 |
| - source_file.lstrip('/') |
| 84 | + src_file.lstrip('/') |
80 | 85 | ]) %}
|
81 | 86 | {{ url | indent(indent_width, true) }}
|
82 | 87 | {%- endfor %}
|
|
0 commit comments