【发布时间】:2018-09-05 17:42:25
【问题描述】:
我在 Python 3 虚拟环境中安装了 Salt,并创建了一个使用非根文件夹存储所有内容的 Salt 配置 (/home/user/saltenv)。在 venv 中使用 salt-ssh 命令时,例如salt-ssh '*' test.ping,一切正常。 (请注意,配置目录是通过Saltfile 解析的,因此省略了-c 选项,但这不重要。)
但是,当直接通过 Python 调用 SSHClient 时,我没有得到任何结果。我已经发现没有读取名册文件,显然会导致一个空的目标列表。我不知何故被卡住了,documentation 没那么有用。
代码如下:
import salt.config
from salt.client.ssh.client import SSHClient
def main():
c_path = '/home/user/saltenv/etc/salt/master'
master_opts = salt.config.client_config(c_path)
c = SSHClient(c_path=c_path, mopts=master_opts)
res = c.cmd(tgt='*', fun='test.ping')
print(res)
if __name__ == '__main__':
main()
【问题讨论】:
标签: python salt salt-stack