How to make saltstack retrieve states from multiple branches in gitfs

1.4k views Asked by At

I have several computers managed by the Saltstack that are used both for production and development.

These PCs are our internal servers and purpose of using Saltstack is (1) to backup settings for quickly reapplying them in case of failures (2) fast setup of a new PC in case it appears. All cases do not happen often, and total amount of servers is less than 10.

Stable states for the Salt are stored in gitfs in the master branch of a dedicated git repository.

Sometimes I need to add new features and start developing new state. Currently I commit directly to master and often my commits break existing configuration because of errors.

I'd like to commit my work in progress in separate git branches and use something like

$ sudo salt minion state.apply my-new-state saltenv=feature/branch

However, I'm getting errors about missing environment instead:

~$ sudo salt minion state.show_sls ups saltenv=feature/ups
minion:
    - No matching salt environment for environment 'feature/ups' found
    - No matching sls found for 'ups' in env 'feature/ups'

My config in /etc/salt/master:

gitfs_saltenv_whitelist:
  - base
  - feature\/*

gitfs_remotes:
  - [email protected]:ci-formula.git

I've seen similar question on serverfault.com, tried proposed solution with dynamic {{saltenv}}. It didn't help

1

There are 1 answers

0
Andrei Kovrov On BEST ANSWER

You missed a dot for your gitfs_saltenv_whitelist regexp rule.

It should be like this

gitfs_saltenv_whitelist:
  - base
  - feature\/.*

gitfs_remotes:
  - [email protected]:ci-formula.git

Also, gitfs is a little bit buggy. It can't stand hard history changes with force pushes.

Check that your files sync from git to salt master cache:

salt-run fileserver.file_list backend=gitfs

If you see nothing try to clear the cache manually

service salt-master stop
rm -rf /var/cache/salt/master/file_lists/*
rm -rf /var/cache/salt/master/gitfs/*
service salt-master start