如何获得未连接的小兵的返回值?

时间:2015-11-06 02:48:56

标签: python salt-stack

我使用Saltstack's python api执行salt命令,代码列在下面。

local = salt.client.LocalClient()
local.cmd(['node1', 'node2', 'node3'], 'cp.get_file', ['salt://file', '/root/file'], expr_form='list')

Minion node3未连接到Master,但node3的返回值未显示在结果中。

{'node1': '/root/file', 'node2': '/root/file'}

但如果我在shell中运行salt 'node[1-3]' cp.get_file salt://file /root/file,则node3的结果应为:node3: Minion did not return. [No response]
那么当我使用Salt的python api时,如何获得node3的结果?

Thx家伙。

1 个答案:

答案 0 :(得分:1)

根据源代码(salt/client/__init__.py),此行为仅适用于cli调用。所以我相信使用python API获取相同的输出格式是不可能的。

但是,通常不需要这样做。鉴于你有一个目标仆从列表,很容易找到哪些仆从没有回应:

local = salt.client.LocalClient()
target = ['node1', 'node2', 'node3']
ret = local.cmd(target, 'cp.get_file', ['salt://file', '/root/file'], expr_form='list')
fails = list(set(target) - set(ret))