Skip to content

Commit 115f638

Browse files
authored
Merge pull request #279 from myii/ci/standardise-structure
chore: use `semantic-release` cross-formula standard structure
2 parents 5df8f79 + 84eef0c commit 115f638

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

docs/TOFS_pattern.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Using SaltStack is a simple and effective way to implement configuration managem
3939

4040
To avoid this situation we can use the `pillar mechanism <http://docs.saltstack.com/en/latest/topics/pillar/>`_, which is designed to provide controlled access to data from the minions based on some selection rules. As pillar data could be easily integrated in the `Jinja <http://docs.saltstack.com/en/latest/topics/tutorials/pillar.html>`_ templates, it is a good mechanism to store values to be used in the final rendering of state files and templates.
4141

42-
There are a variety of approaches on the usage of pillar and templates as seen in the `saltstack-formulas <https://github.com/saltstack-formulas>`_' repositories. `Some <https://github.com/saltstack-formulas/nginx-formula/pull/18>`_ `developments <https://github.com/saltstack-formulas/php-formula/pull/14>`_ stress the initial purpose of pillar data into a storage for most of the possible variables for a determined system configuration. This, in my opinion, is shifting too much load from the original template files approach. Adding up some `non-trivial Jinja <https://github.com/spsoit/nginx-formula/blob/81de880fe0276dd9488ffa15bc78944c0fc2b919/nginx/ng/files/nginx.conf>`_ code as essential part of composing the state file definitely makes SaltStack state files (hence formulas) more difficult to read. The extreme of this approach is that we could end up with a new render mechanism, implemented in Jinja, storing everything needed in pillar data to compose configurations. Additionally, we are establishing a strong dependency with the Jinja renderer.
42+
There are a variety of approaches on the usage of pillar and templates as seen in the `saltstack-formulas <https://github.com/saltstack-formulas>`_' repositories. `Some <https://github.com/saltstack-formulas/nginx-formula/pull/18>`_ `developments <https://github.com/saltstack-formulas/php-formula/pull/14>`_ stress the initial purpose of pillar data into a storage for most of the possible variables for a determined system configuration. This, in my opinion, is shifting too much load from the original template files approach. Adding up some `non-trivial Jinja <https://github.com/saltstack-formulas/nginx-formula/blob/f74254c07e188bd448eaf1c5f9c802d78c4c005e/nginx/files/default/nginx.conf>`_ code as essential part of composing the state file definitely makes SaltStack state files (hence formulas) more difficult to read. The extreme of this approach is that we could end up with a new render mechanism, implemented in Jinja, storing everything needed in pillar data to compose configurations. Additionally, we are establishing a strong dependency with the Jinja renderer.
4343

4444
In opposition to the *put the code in file_roots and the data in pillars* approach, there is the *pillar as a store for a set of key-values* approach. A full-blown configuration file abstracted in pillar and jinja is complicated to develop, understand and maintain. I think a better and simpler approach is to keep a configuration file templated using just a basic (non-extensive but extensible) set of pillar values.
4545

@@ -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

postgres/libtofs.jinja

Lines changed: 21 additions & 15 deletions
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 != '' %}
@@ -83,18 +82,25 @@
8382
{%- for fs in fsl %}
8483
{%- for src_file in src_files %}
8584
{%- if fs %}
86-
{%- set fs_dir = salt['config.get'](fs, fs) %}
85+
{%- set fs_dirs = salt['config.get'](fs, fs) %}
8786
{%- else %}
88-
{%- set fs_dir = salt['config.get'](tplroot ~ ':tofs:dirs:default', 'default') %}
87+
{%- set fs_dirs = salt['config.get'](tplroot ~ ':tofs:dirs:default', 'default') %}
8988
{%- endif %}
90-
{%- set url = [
91-
'- salt:/',
92-
path_prefix_inc_ext.strip('/'),
93-
files_dir.strip('/'),
94-
fs_dir.strip('/'),
95-
src_file.strip('/'),
96-
] | select | join('/') %}
89+
{#- Force the `config.get` lookup result as a list where necessary #}
90+
{#- since we need to also handle grains that are lists #}
91+
{%- if fs_dirs is string %}
92+
{%- set fs_dirs = [fs_dirs] %}
93+
{%- endif %}
94+
{%- for fs_dir in fs_dirs %}
95+
{%- set url = [
96+
'- salt:/',
97+
path_prefix_inc_ext.strip('/'),
98+
files_dir.strip('/'),
99+
fs_dir.strip('/'),
100+
src_file.strip('/'),
101+
] | select | join('/') %}
97102
{{ url | indent(indent_width, true) }}
103+
{%- endfor %}
98104
{%- endfor %}
99105
{%- endfor %}
100106
{%- endfor %}

0 commit comments

Comments
 (0)