SaltStack: Call a single state of a sls file

saltstack

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)

Best Answer

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.