如何在 salt-api 中使用 cmd.run

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" }]'

我想 运行 通过 salt-api 命令。但是我收到一个错误。 test.ping 工作正常。我想我缺少体内的参数。任何人都可以在此处指出文档或调整上面的 curl 命令。谢谢

您将要使用 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"
     }]'

您需要使用模块中函数的名称,而不是状态。

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