How write a custom runner that can be used to preview targets without running commands
search cancel

How write a custom runner that can be used to preview targets without running commands

book

Article ID: 402376

calendar_today

Updated On:

Products

VCF Operations/Automation (formerly VMware Aria Suite)

Issue/Introduction

Some users may find it useful to be able to view which minions are expected to respond to a command prior to actually running any commands. This feature does not actually exist in the production ready (LTS) release of Salt, but is introduced in the 3007.4. Since this is not the LTS release we (VMware Support) do not recommend upgrading just to get this feature. The current LTS release of Salt has the --preview-target option, but this must be used from the CLI of the Salt master and may be tricky to use if you need to execute this from the Aria Config API with Salt versions older than 3007.4. 

Environment

Aria Config - all versions

Tanzu Salt - all versions

Resolution

SaltProject is by design very flexible and extendable. Users are encouraged to write their own modules to include features that may be specific to their environment if and when the need arises. See this documentation for how to get started writing custom modules, https://docs.saltproject.io/en/3006/ref/modules/index.html

Follow these steps on your Salt master

  1. Create a directory called /srv/salt/_runners
  2. Create a file called /srv/salt/_runners/match.py
  3. Download the contents of the file linked from the SaltProject repo atat the end this article.
  4. Save the contents and exit the file.
  5. Run salt-run saltutil.sync_runners

You should see some output indicating that the file was synchronized to the Salt master cache. 

Now test that the runner is functioning as expected by running a command like the following

salt-run match.compound_matches "G@kernel:Linux" "compound"

For the latest copy of this runner, please see https://github.com/saltstack/salt/blob/master/salt/runners/match.py

For documentation getting started using the API in Aria Config, please see https://knowledge.broadcom.com/external/article?articleNumber=375377

Additional Information

3007.4 documentation for feature, https://docs.saltproject.io/en/latest/ref/runners/all/salt.runners.match.html#module-salt.runners.match