diff --git a/kitchen.yml b/kitchen.yml index 3be550ae..60d3e6e6 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -124,8 +124,10 @@ provisioner: base: '*': - template + - define_roles pillars_from_files: template.sls: pillar.example + define_roles.sls: test/salt/pillar/define_roles.sls verifier: # https://www.inspec.io/ diff --git a/pillar.example b/pillar.example index 583a0d6f..2ffdf754 100644 --- a/pillar.example +++ b/pillar.example @@ -33,6 +33,7 @@ template: files_switch: - any/path/can/be/used/here - id + - roles - osfinger - os - os_family diff --git a/template/libtofs.jinja b/template/libtofs.jinja index da656a5e..d830cee2 100644 --- a/template/libtofs.jinja +++ b/template/libtofs.jinja @@ -83,18 +83,25 @@ {%- for fs in fsl %} {%- for src_file in src_files %} {%- if fs %} - {%- set fs_dir = salt['config.get'](fs, fs) %} + {%- set fs_dirs = salt['config.get'](fs, fs) %} {%- else %} - {%- set fs_dir = salt['config.get'](tplroot ~ ':tofs:dirs:default', 'default') %} + {%- set fs_dirs = salt['config.get'](tplroot ~ ':tofs:dirs:default', 'default') %} {%- endif %} - {%- set url = [ - '- salt:/', - path_prefix_inc_ext.strip('/'), - files_dir.strip('/'), - fs_dir.strip('/'), - src_file.strip('/'), - ] | select | join('/') %} + {#- Force the `config.get` lookup result as a list where necessary #} + {#- since we need to also handle grains that are lists #} + {%- if fs_dirs is string %} + {%- set fs_dirs = [fs_dirs] %} + {%- endif %} + {%- for fs_dir in fs_dirs %} + {%- set url = [ + '- salt:/', + path_prefix_inc_ext.strip('/'), + files_dir.strip('/'), + fs_dir.strip('/'), + src_file.strip('/'), + ] | select | join('/') %} {{ url | indent(indent_width, true) }} + {%- endfor %} {%- endfor %} {%- endfor %} {%- endfor %} diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb index 7b7632d2..2c3e795c 100644 --- a/test/integration/default/controls/config_spec.rb +++ b/test/integration/default/controls/config_spec.rb @@ -14,7 +14,7 @@ its('content') { should include '"lookup": {"added_in_lookup": "lookup_value",' } its('content') { should include '"pkg": {"name": "' } its('content') { should include '"service": {"name": "' } - its('content') { should include '"tofs": {"files_switch": ["any/path/can/be/used/here", "id", "osfinger", "os", "os_family"], "source_files": {"template-config-file-file-managed": ["example.tmpl.jinja"]}' } + its('content') { should include '"tofs": {"files_switch": ["any/path/can/be/used/here", "id", "roles", "osfinger", "os", "os_family"], "source_files": {"template-config-file-file-managed": ["example.tmpl.jinja"]}' } its('content') { should include '"winner": "pillar"}' } its('content') { should include 'winner of the merge: pillar' } end diff --git a/test/salt/pillar/define_roles.sls b/test/salt/pillar/define_roles.sls new file mode 100644 index 00000000..6d37f684 --- /dev/null +++ b/test/salt/pillar/define_roles.sls @@ -0,0 +1,4 @@ +# libtofs.jinja must work with tofs.files_switch looked up list +roles: + - foo + - bar