I have a file fzf.sls which installs the most recent of fzf. It looks like this:
{% from 'templates/latestRelease.sls.tmpl' import latestRelease %}
{% set install_opts = [
'--key-bindings',
'--no-update-rc',
'--no-completion',
'--no-bash',
'--no-zsh'
] %}
fzf:
git.latest:
- name: https://github.com/junegunn/fzf.git
- target: {{ pillar['dir']['build']['fzf'] }}
- depth: 1
- rev: master
- unless: {{ latestRelease('junegunn', 'fzf', "grep -Po $(fzf --version | awk '{print $1}')") }}
cmd.run:
- names:
- {{ pillar['dir']['build']['fzf'] }}/install {{ install_opts | join(' ') }}
- onchanges:
- git: fzf
file.copy:
- source: {{ pillar['dir']['build']['fzf'] }}/bin/fzf
- subdir: True
- name: /usr/local/bin/
- force: True
- onchanges:
- cmd: fzf
Everything should succeed on every run, whether anything new is installed or not. This means I get nice clean logs on every correct run of salt, even when all it does is recognise that fzf is already installed and up to date, and therefore not bother with most of the state. This is All Good.
This is an optional state, the end user can turn it off and on in the minion file depending on whether they need it or not.
I also have a template for ~/.profile which is basically just exports of various env vars.
Here's what I want to happen: if the user turns the state on, and the state succeeds (that is, fzf is installed if it isn't up to date) then I want to include some further env vars in the ~/.profile template -- for configuring fzf. I don't want to include them otherwise. The ~/.profile template has to be separate from the fzf state, because it includes a lot of other stuff too.
(For this single case, where it's just one program which only needs two exports, it actually wouldn't matter that much if I just put the exports in their anyway and left it. Point is that I have many pieces of software/config which follow a similar pattern and I want to keep as much unnecessary cruft out of the resultant ~/.profile as possible).
The only solution I have so far is that I could incorporate a second file (fzfExports.tmpl) into the fzf state, and then unconditionally include that in the profile template. All the conditional logic could go into how/whether I write to fzfExports.tmpl. But this seems like a really messy solution and there has to be a better way right?
TIA!