Skip to content

Commit

Permalink
Merge pull request #76 from myii/bug/remove-dupe-files-in-tofs
Browse files Browse the repository at this point in the history
 fix(tofs): use `source_files` instead of `files`
  • Loading branch information
aboe76 authored Mar 9, 2019
2 parents eab481c + 5110716 commit f72c621
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions docs/TOFS_pattern.rst
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ We can simplify the ``conf.sls`` with the new ``files_switch`` macro to use in t
- template: jinja
- source: {{ files_switch(
salt['config.get'](
tplroot ~ ':tofs:files:Configure NTP',
tplroot ~ ':tofs:source_files:Configure NTP',
['/etc/ntp.conf.jinja']
)
) }}
Expand All @@ -326,7 +326,7 @@ We can simplify the ``conf.sls`` with the new ``files_switch`` macro to use in t
- pkg: Install NTP package
* This uses ``config.get``, searching for ``nfs:tofs:files:Configure NTP`` to determine the list of template files to use.
* This uses ``config.get``, searching for ``nfs:tofs:source_files:Configure NTP`` to determine the list of template files to use.
* If this does not yield any results, the default of ``['/etc/ntp.conf.jinja']`` will be used.

In ``macros.jinja``, we define this new macro ``files_switch``.
Expand Down Expand Up @@ -417,16 +417,16 @@ Resulting in:
...
- salt://ntp/files/default_alt/etc/ntp.conf.jinja
Customise the list of template ``files``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Customise the list of ``source_files``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The list of template ``files`` can be given:
The list of ``source_files`` can be given:

.. code-block:: sls
ntp:
tofs:
files:
source_files:
Configure NTP:
- '/etc/ntp.conf.jinja'
- '/etc/ntp.conf_alt.jinja'
Expand Down
4 changes: 2 additions & 2 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ template:
# dirs:
# files: files_alt
# default: default_alt
# files:
# template-config:
# source_files:
# template-config-file-file-managed:
# - 'example_alt.tmpl'
# - 'example_alt.tmpl.jinja'

2 changes: 1 addition & 1 deletion template/config/file.sls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ template-config-file-file-managed:
- name: {{ template.config }}
- source: {{ files_switch(
salt['config.get'](
tplroot ~ ':tofs:files:template-config',
tplroot ~ ':tofs:source_files:template-config-file-file-managed',
['example.tmpl', 'example.tmpl.jinja']
)
) }}
Expand Down
10 changes: 5 additions & 5 deletions template/macros.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- macro files_switch(files,
{%- macro files_switch(source_files,
default_files_switch=['id', 'os_family'],
indent_width=6) %}
{#-
Expand All @@ -7,7 +7,7 @@
Files Switch (TOFS) pattern.
Params:
* files: ordered list of files to look for
* source_files: ordered list of files to look for
* default_files_switch: if there's no pillar
'<tplroot>:tofs:files_switch' this is the ordered list of grains to
use as selector switch of the directories under
Expand All @@ -23,7 +23,7 @@
- name: /etc/yyy/zzz.conf
- source: {{ files_switch(
salt['config.get'](
tplroot ~ ':tofs:files:Deploy configuration',
tplroot ~ ':tofs:source_files:Deploy configuration',
['/etc/yyy/zzz.conf', '/etc/yyy/zzz.conf.jinja']
)
) }}
Expand Down Expand Up @@ -66,7 +66,7 @@
{%- do fsl.append('') %}
{%- endif %}
{%- for fs in fsl %}
{%- for file in files %}
{%- for source_file in source_files %}
{%- if fs %}
{%- set fs_dir = salt['config.get'](fs, fs) %}
{%- else %}
Expand All @@ -76,7 +76,7 @@
path_prefix_inc_ext,
files_dir,
fs_dir,
file.lstrip('/')
source_file.lstrip('/')
]) %}
{{ url | indent(indent_width, true) }}
{%- endfor %}
Expand Down

0 comments on commit f72c621

Please sign in to comment.