J.Wang
J.Wang

Reputation: 1241

How can I get the return value of minions that not connected?

I was using Saltstack's python api to execute salt command and the code lists below.

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

Minion node3 was not connected to the Master, but the return value of node3 was not shown in the results.

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

But if I run salt 'node[1-3]' cp.get_file salt://file /root/file in the shell, the results of node3 should be: node3: Minion did not return. [No response]
So how can I get the results of node3 when I use Salt's python api?

Thx guys.

Upvotes: 0

Views: 489

Answers (1)

frizzby
frizzby

Reputation: 419

According to source code (salt/client/__init__.py) this behaviour is specific to cli invocation only. So i believe it is impossible to get the same output format using python API.

However, usually this is not needed. Given you have a list of target minions, it's easy to find what minions did not respond:

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))

Upvotes: 1

Related Questions