Salt Python API 到 运行 状态

Salt Python API to run states in minion

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

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

我可以在 python 脚本中做这样的事情吗?

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

是的,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

更新后的代码应该是

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'},}
  )