-2

I'm trying to apply a salt state to my non prod environment at /srv/salt/non-prod I'm getting this result:

[root@salt non-prod]# salt '*' state.apply
salt.localdomain:
----------
          ID: states
    Function: no.None
      Result: False
     Comment: No Top file or external nodes data matches found.
     Changes:

Summary for salt.localdomain
------------
Succeeded: 0
Failed:    1

I have this location defined in my master config

   non-prod:
     - /srv/non-prod
     - /srv/salt/non-prod/services
     - /srv/salt/non-prod/states

I have a top file located here:

[root@salt ~]# cat /srv/salt/non-prod/top.sls
base:
  '*':
    - apache
    - python
    - ssh
    - users

These are the contents of the non-prod directory

  [root@salt ~]# ls -lh /srv/salt/non-prod/
total 16K
drwxr-xr-x. 2 root root 4.0K Oct  3 21:02 apache
drwxr-xr-x. 2 root root   45 Oct  3 20:57 python
drwxr-xr-x. 2 salt salt    6 Oct  3 14:10 services
drwxr-xr-x. 2 root root   54 Oct  3 18:23 ssh
drwxr-xr-x. 2 salt salt    6 Oct  3 14:10 states
-rw-r--r--. 1 root root   80 Oct  3 15:29 state.template
-rw-r--r--. 1 root root  174 Oct  3 15:30 test.sls
-rw-r--r--. 1 root root   61 Oct  3 21:14 top.sls
drwxr-xr-x. 2 root root   22 Oct  3 21:03 users
drwxr-xr-x. 2 salt salt   99 Oct  3 18:28 webserver

it contains a few salt modules

How can I apply salt states to just the non-prod environment?

Dan Getz
  • 8,774
  • 6
  • 30
  • 64
bluethundr
  • 1,005
  • 17
  • 68
  • 141

1 Answers1

4

If you check the syntax using some yaml validation tools, then we can go to next step.

Read saltstack top documentation thoroughly, you will notice setting different environment, you first explicitly define alternate environment name on /etc/salt/master and also specify it under top.sls

i.e., you file_roots specify the non-prod environment

file_roots:
  #non-prod environment
  non-prod:
    - /srv/non-prod
    - /srv/salt/non-prod/services
    - /srv/salt/non-prod/states

Thus your top.sls should use the environment name non-prod , not base

non-prod:
  '*':
    - apache
    - python
    - ssh
    - users

Since saltstack always use "base" environment by default, you should apply the state explicitly.

salt '*' state.highstate saltenv=non-prod
mootmoot
  • 12,845
  • 5
  • 47
  • 44
  • 1
    That works. But how I solved the problem was by setting the environment: non-prod variable in the /etc/salt/minion config. Restarting the minion service got this to work. I also tested your method and I got it working that way as well. Thanks! – bluethundr Oct 12 '16 at 13:24