Search code examples
salt-project

Running multiple states in a sub-directory


I want to run multiple states with one command but as a test I'm just using one to see if it works.

Anyways when I run

sudo salt 'minion' state.apply DirectX

it works as it should installing it. But this is when it is located in /srv/salt.

When I create a new directory /srv/salt/windows/states and put my SLS files there, like DirectX.sls from before. Then I create a new SLS called runall.sls in /srv/salt. I steup runall.sls like:

base:
  '*':
    - windows.states.DirectX

and run

sudo salt 'dss' state.sls runall

I get:

minion:
----------
          ID: base
    Function: minion.windows.states.DirectX
      Result: False
     Comment: State '*.windows.states.DirectX' was not found in SLS 'runall'
              Reason: '*.windows.states.DirectX' is not available.
     Changes:

Summary for minion
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   0.000 ms

I know I'm definitely doing something wrong because this should be simple but if you could just point me in the right direction that would be great.

Salt Version: 2016.3.4 (Both minion and master) OS: Red Hat Enterprise Linux Server 6.6 Santiago


Solution

  • You need to distinguish between top files and common state files - both by default have the .sls file suffix.

    The top files are basically used to bundle states together on minions or groups of minions and states are there to really configure something specific.

    Usually there is one top.sls for your environment which knows about which minions should have which states. If you afterwards use salt '*' state.highstate all states configured for your minion were applied.

    Depending on your needs it might be a good idea to have different top files. You can use salt '*' state.top /path/to/another_top.sls to apply this specific top file.

    There is also another approach without using top files at all to achieve what you asking for.

    Inside of states there is include [1]. You might consider creating in /srv/salt/bundleX.sls that just uses the include directive to bundle together your windows states like this:

    include:
      - windows.states.DirectX
      - windows.states.Foobar
    

    But if there is nothing against top.sls, a would recommend using the top file as described above.