Skip to content

Commit 3483e76

Browse files
committed
fix(tofs): prepend the config-based source_files to the default
* saltstack-formulas/nginx-formula#247 (comment) - The main issue is that the `nginx-formula` has dynamic values being used as the default `source_files` -- there is no way to provide this from the pillar/config in a sensible fashion - Prepending to this default (rather than overriding it) resolves this problem entirely, without adding excessive entries to the `source` * Closes #151
1 parent d05d444 commit 3483e76

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

Diff for: docs/TOFS_pattern.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ We can simplify the ``conf.sls`` with the new ``files_switch`` macro to use in t
325325
326326
327327
* 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.
328329
* If this does not yield any results, the default of ``['/etc/ntp.conf.jinja']`` will be used.
329330

330331
In ``libtofs.jinja``, we define this new macro ``files_switch``.
@@ -426,18 +427,20 @@ The list of ``source_files`` can be given:
426427
tofs:
427428
source_files:
428429
Configure NTP:
429-
- '/etc/ntp.conf.jinja'
430430
- '/etc/ntp.conf_alt.jinja'
431431
432432
Resulting in:
433433

434434
.. code-block:: sls
435435
436436
- source:
437-
- salt://ntp/files/theminion/etc/ntp.conf.jinja
438437
- 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
440439
- 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
442441
- 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.
443446

Diff for: pillar.example

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ template:
4343
# dirs:
4444
# files: files_alt
4545
# default: default_alt
46+
# The entries under `source_files` are prepended to the default source files
47+
# given for the state
4648
# source_files:
4749
# template-config-file-file-managed:
4850
# - 'example_alt.tmpl'

Diff for: template/config/file.sls

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include:
1313
template-config-file-file-managed:
1414
file.managed:
1515
- name: {{ template.config }}
16-
- source: {{ files_switch(['example.tmpl', 'example.tmpl.jinja'],
16+
- source: {{ files_switch(['example.tmpl'],
1717
lookup='template-config-file-file-managed'
1818
)
1919
}}

Diff for: template/libtofs.jinja

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
Params:
1212
* 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
1414
list of source files
1515
* default_files_switch: if there's no config (e.g. pillar)
1616
'<tplroot>:tofs:files_switch' this is the ordered list of grains to
@@ -55,14 +55,13 @@
5555
tplroot ~ ':tofs:files_switch',
5656
default_files_switch
5757
) %}
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 #}
5959
{%- set src_files = salt['config.get'](
6060
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, [])
6562
) %}
63+
{#- Append the default source_files #}
64+
{%- set src_files = src_files + source_files %}
6665
{#- Only add to [''] when supporting older TOFS implementations #}
6766
{%- set path_prefix_exts = [''] %}
6867
{%- if v1_path_prefix != '' %}

0 commit comments

Comments
 (0)