Search code examples
pythonsalt-project

Salt Python API to run states in minion


Can i run my state using python api ?

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

Can i do something like this in python script ?

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

Solution

  • Yes, salt Client API can do what you want, your code just need to change a bit:

    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 Salt Python client API docs for more detail