标签:获取 tgt 批量 return saltstack list mod lan app
import salt.config
master_opts = salt.config.client_config(‘/etc/salt/master‘)
print master_opts
import salt.client
local = salt.client.LocalClient()
ret = local.cmd(tgt=‘roles:salt-master‘, fun=‘test.version‘, tgt_type=‘grain‘, full_return=True)
print ret
ret1 = local.cmd_batch(tgt="roles:salt-slave", fun="cmd.run", arg=(["ping -c 10 baidu.com"]), tgt_type=‘grain‘)
for i in ret1:
print i
modules = local.cmd("n1", fun="sys.list_modules")
for module in modules["n1"]:
local.cmd(‘n1‘, fun="file.touch", arg=(["/root/salt_"+module+"_doc.md"]))
module_doc = local.cmd(‘n1‘, fun="sys.doc", arg=([module]))
doc = module_doc["n1"]
for i in doc:
key = i.encode("raw_unicode_escape")
local.cmd("n1", fun="file.append", arg=(["/root/salt_"+module+"_doc.md", key]))
print key
value = doc[key].encode("raw_unicode_escape")
local.cmd("n1", fun="file.append", arg=(["/root/salt_"+module+"_doc.md", value]))
print value
标签:获取 tgt 批量 return saltstack list mod lan app
原文地址:https://www.cnblogs.com/randomlee/p/12588311.html