File tree 4 files changed +15
-11
lines changed
4 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -325,6 +325,7 @@ We can simplify the ``conf.sls`` with the new ``files_switch`` macro to use in t
325
325
326
326
327
327
* This uses ``config.get ``, searching for ``ntp:tofs:source_files:Configure NTP `` to determine the list of template files to use.
328
+ * If this returns a result, the default of ``['/etc/ntp.conf.jinja'] `` will be appended to it.
328
329
* If this does not yield any results, the default of ``['/etc/ntp.conf.jinja'] `` will be used.
329
330
330
331
In ``libtofs.jinja ``, we define this new macro ``files_switch ``.
@@ -426,18 +427,20 @@ The list of ``source_files`` can be given:
426
427
tofs:
427
428
source_files:
428
429
Configure NTP:
429
- - '/etc/ntp.conf.jinja'
430
430
- '/etc/ntp.conf_alt.jinja'
431
431
432
432
Resulting in:
433
433
434
434
.. code-block :: sls
435
435
436
436
- source:
437
- - salt://ntp/files/theminion/etc/ntp.conf.jinja
438
437
- salt://ntp/files/theminion/etc/ntp.conf_alt.jinja
439
- - salt://ntp/files/Debian /etc/ntp.conf.jinja
438
+ - salt://ntp/files/theminion /etc/ntp.conf.jinja
440
439
- salt://ntp/files/Debian/etc/ntp.conf_alt.jinja
441
- - salt://ntp/files/default /etc/ntp.conf.jinja
440
+ - salt://ntp/files/Debian /etc/ntp.conf.jinja
442
441
- salt://ntp/files/default/etc/ntp.conf_alt.jinja
442
+ - salt://ntp/files/default/etc/ntp.conf.jinja
443
+
444
+ Note: This does *not * override the default value.
445
+ Rather, the value from the pillar/config is prepended to the default.
443
446
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ template:
43
43
# dirs:
44
44
# files: files_alt
45
45
# default: default_alt
46
+ # The entries under `source_files` are prepended to the default source files
47
+ # given for the state
46
48
# source_files:
47
49
# template-config-file-file-managed:
48
50
# - 'example_alt.tmpl'
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ include:
13
13
template- config- file - file - managed:
14
14
file .managed:
15
15
- name: {{ template.config }}
16
- - source: {{ files_switch([' example.tmpl' , ' example.tmpl.jinja ' ],
16
+ - source: {{ files_switch([' example.tmpl' ],
17
17
lookup = ' template-config-file-file-managed'
18
18
)
19
19
}}
Original file line number Diff line number Diff line change 10
10
11
11
Params:
12
12
* source_files: ordered list of files to look for
13
- * lookup: key under '<tplroot>:tofs:source_files' to override
13
+ * lookup: key under '<tplroot>:tofs:source_files' to prepend to the
14
14
list of source files
15
15
* default_files_switch: if there's no config (e.g. pillar)
16
16
'<tplroot>:tofs:files_switch' this is the ordered list of grains to
55
55
tplroot ~ ':tofs:files_switch' ,
56
56
default_files_switch
57
57
) %}
58
- {#- Lookup source_files (v2), files (v1), or fallback to source_files parameter #}
58
+ {#- Lookup source_files (v2), files (v1), or fallback to an empty list #}
59
59
{% - set src_files = salt ['config.get' ](
60
60
tplroot ~ ':tofs:source_files:' ~ lookup ,
61
- salt ['config.get' ](
62
- tplroot ~ ':tofs:files:' ~ lookup ,
63
- source_files
64
- )
61
+ salt ['config.get' ](tplroot ~ ':tofs:files:' ~ lookup , [])
65
62
) %}
63
+ {#- Append the default source_files #}
64
+ {% - set src_files = src_files + source_files %}
66
65
{#- Only add to [''] when supporting older TOFS implementations #}
67
66
{% - set path_prefix_exts = ['' ] %}
68
67
{% - if v 1_path_prefix != '' %}
You can’t perform that action at this time.
0 commit comments