saltstack-formulas / template-formula

SaltStack formula template filled with dummy content

Home Page:http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change file_switch to append source_file lookups, rather than override

ErisDS opened this issue ยท comments

To give a concrete example from nginx-formula:

 {{ files_switch([server, 'server.conf'],
                      'server_conf_file_managed'
         )
      }}

On any given host, I may have many managed server values. Therefore, it's important that it's possible to use the dynamic server filename.

If I configure nginx.tofs.source_files.server_conf_file_managed to, e.g. default.conf, I expect this to be appended to the list of files that get looked for.

However instead, nginx-formula will now only look for default.conf, removing the ability to have multiple servers per host.

My expectation is that setting server_conf_file_managed adds a cascading override - i.e. it appends to the beginning of the list of file names to look for, not overrides the full existing list.

Thanks @ErisDS. Note for others, this issue was discussed in Slack. I put forward a potential solution (appending the original source_files rather than overriding it) which is working for us both:

  {#- Lookup source_files (v2), files (v1), or fallback to an empty list #}
  {%- set src_files = salt['config.get'](
      tplroot ~ ':tofs:source_files:' ~ lookup,
      salt['config.get'](
          tplroot ~ ':tofs:files:' ~ lookup,
          []
      )
  ) %}
  {#- Append source_files #}
  {%- set src_files = src_files + source_files %}

I'll put that in a PR soon, so that it can be discussed further.

๐ŸŽ‰ This issue has been resolved in version 3.1.1 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€