Saltstack is historically and by design is not about working with runtime information. One of the features that'd like to see is a requisite which are based on some runtime info.
Here is an example:
I want to run some state but only if the result of the different module is True.
It may look like this:
cmd.run:
<...>
- onlyif: my_custom_module_which_returns_true_or_false
And I want to do it in runtime, not before via Jinja execution of the Salt.
I think it's already possible with slots and onlyif in a way that if slots function will return a string "true" or "false", onlyif will execute it on the system and make a decision based on this.
The executing a shell part is really not necessary and this whole approach is hacky so if we may have a new requisite module just for this that'd be really great.
This idea is inspired by Ansible's condition engine, which allows doing this:
name: Run command
command: "ls -1 /tmp"
register: result_of_command
name: Do something if you should
when: "'file123' in result_of_command.stdout_lines"
module_name:
<...>
will approve as a feature request. thanks :)
This is a duplicate of #5050
And i am working on implementing it right now.
Most helpful comment
PR https://github.com/saltstack/salt/pull/51846