17

I fail to call a single state of an sls file.

Whole sls file works

This works:

salt-ssh w123 state.sls monitoring

This works:

salt-ssh w123 state.show_sls monitoring

One item of above output:

monitoring_packages:
    ----------
    __env__:
        base
    __sls__:
        monitoring.packages
    pkg:
        |_
          ----------
          pkgs:
              - python-psutil
        - installed
        |_
          ----------
          order:
              10000

What I tried

Now I want to call only monitoring_packages, not the whole sls file:

Fails:

salt:/srv # salt-ssh w123 state.sls_id monitoring_packages  monitoring
w123:
    Data failed to compile:
----------
    No matching sls found for 'monitoring' in env 'base'

Fails:

salt:/srv # salt-ssh w123 state.single monitoring.monitoring_packages
w123:
    TypeError encountered executing state.single: single() takes at least 2 arguments (1 given)

Question

How to call my single state monitoring_packages?

Version

salt:/srv # salt-ssh --version
salt-ssh 2015.8.3 (Beryllium)

4 Answers 4

15

I came across this post while also trying to figure out how to do this with regular salt calls (ie. not salt-ssh).

If you have the following SLS file (foo.sls):

bar:
   file.managed:
       - source: salt://some/file

You can run the following command to only execute that entry in the state file:

salt '*' state.sls_id bar foo

And again, I didn't know this either. I found the answer in a comment in a Google group discussion which pointed to a commit here.

2

Looks like this is an already known issue: https://github.com/saltstack/salt/issues/29253

It does work outside of salt-ssh. Looks like a the function needs to be added to that wrapper.

1
salt '*target*' state.sls  monitoring.<sls_file_name> <task name> -l debug

Example: Suppose I have a state for elasticserach with a sls file named settings.sls and inside that file suppose I have task restart_elastic_search, now I want to call this specific task.

salt '*elastic*' state.sls  elasticsearch.settings restart_elastic_search -l debug
1
  • This also worked with salt-call if you're trying to run specific tasks when on the minion terminal: salt-call state.sls <...> -l info Jul 16, 2020 at 0:15
0

Salt and Salt-SSH have the same commands, so no worries there.

Syntax is:

# Pseudo code
Action + Minion-Target/s + State_Apply_Action State_file_name 

# Examples:  

salt \* state.apply myStateFile_under_base

# Nested State file
salt \* state.apply firstDirUnderBase\myStateFile

# Target only Linux Minions 
salt -G 'kernel:linux' state.apply myStateFile_under_base

Notice there is NO .sls on the end of the state file when you run the command! Perhaps this was not true before, but in Salt 3005 it seems to be the case. However, when creating the state file the .sls extension is indeed obligatory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .