Search code examples
salt-project

How to change default saltenv?


I'm trying to change the default saltenv value on my salt master.

I need that all minions get the production environment from my salt master. Il removed the base environment, and made the following configurations :

file_roots:
  production:
    - /srv/salt/production/states
    - /srv/salt/production/formulas
pillar_roots:
  production:
    - /srv/salt/production/pillar

And :

state_top_saltenv: production
default_top: production
top_file_merging_strategy: same

But, when I run :

salt 'myminion' state.highstate I get : No Top file or master_tops data matches found. Please see master log for details.

Running state.apply, it works.

Why is this ? How to get state.apply and state.highstate behave accordingly ?

I came with those settings by trying to understand the documentation, but I know it's not configured the way I want it :

  • the production environment should be the only one to be selected on minion scheduled run
  • environments should be isolated, no merging of data from different environments
  • ability to configure individual minions to run a different saltenv
  • ability to run a specific saltenv from the master (with saltenv=devel for instance)

Solution

  • What I have done to move from base saltenv to production one is the following:

    • in states top.sls, change all base: occurence
    • in pillars top.sls, do the same
    • in minion configuration specify its env with saltenv: production

    Last step may be unneeded if you use default_top: production.

    I think that's all, I have some minimal code with kitchen tests to validate it that I can share if you need it.

    update: default_top: production is sufficient for highstates to run correctly, but is not enough if you want to run specific states (with salt <minion> state.sls foo) => you will need to specify saltenv argument in the command-line or add it to your minion config