Salt Python API在minion中运行状态

时间:2015-04-28 13:13:13

标签: python salt-stack

我可以使用python api运行我的状态吗?

salt -N' test_server' state.sls django这将在我的测试小兵中安装django

我可以在python脚本中执行类似的操作吗?

import salt.client as client
c = client.LocalClient()
c.cmd('test_server','django',expr_form='nodegroup',pillar={'status':'TEST'})

2 个答案:

答案 0 :(得分:5)

是的,salt Client API可以做你想要的,你的代码只需要改变一下:

import salt.client as client
c = client.LocalClient()
c.cmd('test_server',  # target 
      'state.sls',    # function
      ['django', pillar={'status':'TEST'}],  # arg for function
      expr_form='nodegroup',  
      )

请参阅Salt Python client API docs了解更多详情

答案 1 :(得分:0)

更新的代码应为

import salt.client as client
c = client.LocalClient()
c.cmd('test_server',  # target 
  'state.sls',    # function
  ['django'],  # arg for function
  expr_form='nodegroup',
  kwarg={'pillar':{'status':'TEST'},}
  )