Salt Python API for triggering states in minion

Can I start my state using the python api?

salt -N 'test_server' state.sls django, this will install django in my test minion

Can I do something like this in a python script?

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

      

+3


source to share


2 answers


Yes, the salt API client can do what you need, your code just needs to be changed a little:

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

      



see the Salt Python client API docs for more details

+5


source


The updated code should be



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

      

0


source







All Articles