'salt execute command on master

I have a .sls file to install Prometheus on minions, after it's done, I'd like to execute shell command on Salt master to add hostname of just provisioned minion to node_exporter.json file instead of manually editing this dynamic list of hosts to scrape. How can I achieve that? I need func similar to Ansible local_action.



Solution 1:[1]

Your question does not have any details of the "shell command" or logic of updating minion details to node_exporter.json file. So I will directly come to this part:

I need func similar to Ansible local_action.

In Saltstack there is no targeting mechanism from an SLS file. The salt and salt-call commands are the ones to use to target (like ansible ad-hoc command line).

So running the below command on Salt master...

salt-call --local test.ping 

... would be similar to:

ansible localhost -m ping

So if you had an SLS file or shell command to update the node_exporter.json file, you could run it with salt-call --local on the Salt master. E.g.:

salt-call --local cmd.run <your shell command>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 seshadri_c