Skip to content

Commit

Permalink
Merge pull request #1 from myii/bug/tofsv2
Browse files Browse the repository at this point in the history
fix(tofs): use `tpldir` derivative `topdir` for pillar (config) paths
  • Loading branch information
claudekenni authored Feb 25, 2019
2 parents f5dbed6 + 1bf5445 commit d145125
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
9 changes: 6 additions & 3 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ stack:
# default: default_alt
# files:
# stack-config:
# - 'example_alt.tmpl'
# - 'example_alt.tmpl.jinja'

# - 'sdb.conf'
# - 'sdb_alt.conf'
# stack-keys-config:
# - 'sdb_keys.conf'
# - 'sdb_keys_alt.conf'

6 changes: 4 additions & 2 deletions stack/config.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `topdir` from `tpldir` #}
{%- set topdir = tpldir.split('/')[0] %}
{%- from "stack/map.jinja" import stack with context %}
{%- from "stack/macros.jinja" import files_switch with context %}
{% set map = salt['slsutil.renderer']("salt://stack/map.sls") %}
Expand All @@ -10,7 +12,7 @@ stack-config:
- name: {{ stack.sdb.config }}
- source: {{ files_switch(
salt['config.get'](
tpldir ~ ':tofs:files:stack-config',
topdir ~ ':tofs:files:stack-config',
['sdb.conf']
)
) }}
Expand All @@ -36,7 +38,7 @@ stack-keys-config:
- name: {{ stack.sdb.sdb_keys }}
- source: {{ files_switch(
salt['config.get'](
tpldir ~ ':tofs:files:stack-config',
topdir ~ ':tofs:files:stack-keys-config',
['sdb_keys.conf']
)
) }}
Expand Down
52 changes: 32 additions & 20 deletions stack/macros.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,42 @@
- salt://xxx/files/default/etc/yyy/zzz.conf.jinja
- stack: jinja
#}
{%- set path_prefix = salt['config.get'](tpldir ~ ':tofs:path_prefix', tpldir) %}
{%- set files_dir = salt['config.get'](tpldir ~ ':tofs:dirs:files', 'files') %}
{#- Get the `topdir` from `tpldir` #}
{%- set topdir = tpldir.split('/')[0] %}
{%- set path_prefix = salt['config.get'](topdir ~ ':tofs:path_prefix', topdir) %}
{%- set files_dir = salt['config.get'](topdir ~ ':tofs:dirs:files', 'files') %}
{%- set files_switch_list = salt['config.get'](
tpldir ~ ':tofs:files_switch',
topdir ~ ':tofs:files_switch',
default_files_switch
) %}
{#- Append an empty value to evaluate as `default` in the loop below #}
{%- if '' not in files_switch_list %}
{%- do files_switch_list.append('') %}
{%- endif %}
{%- for fs in files_switch_list %}
{%- for file in files %}
{%- if fs %}
{%- set fs_dir = salt['config.get'](fs, fs) %}
{%- else %}
{%- set fs_dir = salt['config.get'](tpldir ~ ':tofs:dirs:default', 'default') %}
{%- endif %}
{%- set url = '- salt://' ~ '/'.join([
path_prefix,
files_dir,
fs_dir,
file.lstrip('/')
]) %}
{#- Only add to [''] when supporting older TOFS implementations #}
{%- for path_prefix_ext in [''] %}
{%- set path_prefix_inc_ext = path_prefix ~ path_prefix_ext %}
{#- For older TOFS implementation, use `files_switch` from the pillar #}
{#- Use the default, new method otherwise #}
{%- set fsl = salt['pillar.get'](
topdir ~ path_prefix_ext|replace('/', ':') ~ ':files_switch',
files_switch_list
) %}
{#- Append an empty value to evaluate as `default` in the loop below #}
{%- if '' not in fsl %}
{%- do fsl.append('') %}
{%- endif %}
{%- for fs in fsl %}
{%- for file in files %}
{%- if fs %}
{%- set fs_dir = salt['config.get'](fs, fs) %}
{%- else %}
{%- set fs_dir = salt['config.get'](topdir ~ ':tofs:dirs:default', 'default') %}
{%- endif %}
{%- set url = '- salt://' ~ '/'.join([
path_prefix_inc_ext,
files_dir,
fs_dir,
file.lstrip('/')
]) %}
{{ url | indent(indent_width, true) }}
{%- endfor %}
{%- endfor %}
{%- endfor %}
{%- endmacro %}

0 comments on commit d145125

Please sign in to comment.