Using THE SAME SLS files from Gitfs across MULTIPLE environments

356 views
Skip to first unread message

mahr...@gmail.com

unread,
May 26, 2016, 3:33:29 PM5/26/16
to Salt-users
I have a set of SLS files including top.sls in a GIT repo.
I have multiple environments like DEV, UAT, T25 etc. that have to use THE SAME SLS files.
State files are ONLY kept in GitFS

/etc/salt/master
-------------------------------------------------------
gitfs_remotes:
   - ssh://user@gitserver/git/sls.git:
     - name: salt
     - base: master
     - root: linux/dev/saltstack/srv/salt
     - mountpoint: salt://salt
  - ssh://user@gitserver/git/sls.git:
    - name: pillar
    - base: master
    - root: linux/dev/saltstack/srv/pillar
    - mountpoint: salt://pillar

The above configuration only maps SLS files to BASE, and I need them to be mapped to ALL other environments i.e. DEV, UAT, T25 etc.

Note, this can be easily done WITHOUT GitFS by placing SLS files into /srv/salt/ and /srv/pillar/ and configuring 'file_roots' and 'pillar_roots':
    /etc/salt/master
    ---------------------
      file_roots:
        base:
           - /srv/salt
        UAT:
           - /srv/salt
        T25:
           - /srv/salt

My interest however is to achieve this WITH GitFS, which I failed so far.

mahr...@gmail.com

unread,
Jun 2, 2016, 2:45:38 PM6/2/16
to Salt-users
Looks like there is no ready answer to this.
One solution to circumvent GitFs' shortcomings is to use Salt Git module that provides multiple functions to manipulate Git as described e.g. here:
"Salt git integration without gitfs" https://clinta.github.io/salt-git-nogitfs/

Jeremy McMillan

unread,
Jun 11, 2016, 5:22:15 PM6/11/16
to Salt-users
Minions should not have environment set in their configuration. Setting environments via top.sls files allows minions to get sls files from multiple environments. To keep things simple, all minions should get appropriate sls files from the base environment. GitFS maps the base environment to the master branch of the underlying git repo. GitFS maps all other environments to git branches of the same name.

SLS files that all environments should share should be merged down to the git master branch. Files (or versions of files) that should only be applied to a particular environment should only exist in the git branch named after that environment. Files that should only ever be applied to a particular environment should be applied to a git repo with an empty master branch, and all commits to those files should be made to the target environment's branches.

Steve Hajducko

unread,
Jun 11, 2016, 5:30:59 PM6/11/16
to Salt-users
FWIW, even setting the environment in a minion's configuration doesn't prevent it from accessing sls files from other environments.  It just sets the default environment that the minion will see.  You can still use the env argument to view a different environment.

Charles McLaughlin

unread,
Jun 14, 2016, 10:06:47 PM6/14/16
to Salt-users
It's been a while since I played with gitfs, but I'd like to point out that you can use {{ env }} in your top.sls files to match all environments.  For instance:

{{ env }}:
  'host':
    - state

If memory serves me, when I tested gitfs I setup a cronjob to clone my remote repo to the local filesystem on my saltmaster and periodically fetched all the remote branches.  Then I think {{ env }} mapped to all of the git branches.  That might be a little easier than the "Salt git integration without gitfs" example... but that's a good one too.
Reply all
Reply to author
Forward
0 new messages