Search code examples
pythonpattern-matchingvirtualenvsalt-project

Salt-Stack: executes states matching a pattern


I want to execute states which match a pattern.

The sls file is called "echo_loop_for_all_systems_of_minion" and in my directory "examples".

I found a way to display the rendered sls file:

salt-ssh  bar-foo state.show_sls  examples.echo_loop_for_all_systems_of_minion

Output:

bar-foo:
    ----------
    modfoo_bar_p_echo:
        ----------
        __sls__:
            examples.echo_loop_for_all_systems_of_minion
        cmd:
            |_
              ----------
              name:
                  /home/modfoo_bar_p/bin/python -c "..."
            - run

    modfoo_bar_q_echo:
        ----------
        __sls__:
            examples.echo_loop_for_all_systems_of_minion
        cmd:
            |_
              ----------
              name:
                  /home/modfoo_bar_q/bin/python -c "..."
            - run

The above file is truncated. I want to run all states which match on this pattern modfoo_bar_*_echo.

Background: We have N systems (python virtualenv) on one minion. I need a way to address only some of them.


Solution

  • Conceptually, you just write a custom module and put it in your /srv/salt/_modules directory on the master.

    Then you call the module from the command-line and pass the filter info into it as parameters.

    Here's an request/example that may help you find the data you will need.