SaltStack: Call a single state of a sls file

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)

Solution 1:

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.

Solution 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.

Solution 3:

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