salt -N 在saltapi中如何使用
时间: 2024-05-06 10:16:54 浏览: 79
在Salt API中,您可以使用salt命令的`-N`选项来选择目标主机。要使用`-N`选项,请执行以下步骤:
1. 打开Salt API配置文件(通常位于`/etc/salt/master`)并确保以下选项已启用:
```
rest_cherrypy:
cors: '*'
disable_ssl: True
port: 8000
debug: True
webhook_disable_auth: True
webhook_url: /hook
webhook_secret: mysecret
webhook_disable_ssl_verify: True
access_control_allow_origin: '*'
access_control_allow_methods: 'GET, POST, PUT, DELETE, OPTIONS'
access_control_allow_headers: 'Authorization, Content-Type, X-Auth-Token, X-Requested-With'
```
注意:这只是一个示例配置文件,并不适用于所有情况。您应该根据自己的需求进行修改。
2. 启动Salt API服务:
```
systemctl start salt-api
```
3. 使用curl或其他HTTP客户端向Salt API发送POST请求。例如:
```
curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"client": "local", "tgt": "web*", "fun": "test.ping", "-N": "web1"}' http://localhost:8000/
```
这个例子中,`-N`选项将目标主机限制为`web1`。如果您想要选择多个主机,可以使用逗号分隔它们:
```
-N 'web1,web2,web3'
```
希望以上内容能够对您有所帮助!
阅读全文
相关推荐

















