Search code examples
salt-project

How to use cmd.run in salt-api


curl -skS "https://xx.xxx.xxx.xxx:8080/run"     -H 'Accept: application/x-yaml'     -H 'Content-type: application/json'     -d '[{
        "client": "local",
        "tgt": "*",
        "fun": "cmd.run",
        "name": "df -h",
        "username": "ravi",
        "password": "teledna",
        "eauth": "pam" }]'

I want to run a command through the salt-api. But I am getting an error. Where test.ping is working fine. I think I am missing the params in the body. Can anybody point out the documentation or adjust the curl command above here. Thanks.


Solution

  • You will want to use cmd

    curl -skS https://xxx.xxx.xxx.xxx:8080/run \
        -H 'Accept: application/x-yaml' \
        -H 'Content-type: application/json' \
        -d '[{
            "client": "local",
            "tgt": "*",
            "fun": "cmd.run",
            "kwarg": {
               "cmd": "df -h"
            },
            "username": "ravi",
            "password": "teledna",
            "eauth": "auto"
         }]'
    

    You need to use the name from the function in the modules, not the state.

    https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.cmdmod.html#salt.modules.cmdmod.run