salt-run state.orch call via salt-api

260 views
Skip to first unread message

Sam Pipe

unread,
Jul 6, 2015, 8:28:36 PM7/6/15
to salt-...@googlegroups.com
Hi,

I'm planning on using salt-api and cherrypy to submit commands to our salt master from a remote server.  I have this working great when it comes to running modules ... but we utilise "salt-run state.orch" to run deployments of applications to the minions.

Does the salt-api include capibility to initiate this type of salt-run command?

eg of one of our deployment commands is below.  The pillar is passed in to :

salt-run state.orch orchestrate.new-tomcat pillar=‘{app_name: test, env_name: uat}’

Any pointers are most appreciated.

Sam

Christian McHugh

unread,
Jul 6, 2015, 11:31:59 PM7/6/15
to salt-...@googlegroups.com
Greetings! 

I was working on the same thing for the jenkins saltapi plugin. I think you may want to do something like:
[
  {
    "client": "runner",
    "expr_form": "glob",
    "fun": "state.orchestrate",
    "mods": "orchestration.refresh-apache",
    "pillar": {
      "target": "dyno2v8"
    },
    "tgt": "dynocache2*"
  }
]

I left a tgt in there, but don't think it's necessary. Note the different than normal semantics of the mods key for the orchestration job to be run and the use of a pillar key instead of passing the data in kwargs.

Anyway, that seems to work for me, so hopefully that helps.

Sam Pipe

unread,
Jul 7, 2015, 5:02:05 AM7/7/15
to salt-...@googlegroups.com
Huge thanks Christian!.. I'll give this a go tomorrow and come back if I have any questions.. 

Much appreciated.

Sam

Sam Pipe

unread,
Jul 20, 2015, 7:45:38 PM7/20/15
to salt-...@googlegroups.com
Hey Christian,

I've finally got back onto this and have hit a odd error... just wondering if you encountered it.  It seems that it doesn't recognise my pillar as a dictionary... If i print the __class__ of the pillar dictionary object it shows it as a dict so I'm slightly confused.


[root@lux2124 pipes]# ./salt-api-call.sh 
data struct to send
{'mods': 'orchestrate.update-tomcats', 'tgt': '*', 'pillar': {'env_name': 'bat', 'app_name': 'demo'}, 'expr_form': 'glob', 'client': 'runner', 'fun': 'state.orchestrate'}

type of data['pillar']
<type 'dict'>
return:
- "Exception occurred in runner state.orchestrate: Traceback (most recent call last):\n\
  \  File \"/usr/lib/python2.7/site-packages/salt/client/mixins.py\", line 317, in\
  \ low\n    data['return'] = self.functions[fun](*args, **kwargs)\n  File \"/usr/lib/python2.7/site-packages/salt/runners/state.py\"\
  , line 105, in orchestrate\n    'Pillar data must be formatted as a dictionary'\n\
  SaltInvocationError: Pillar data must be formatted as a dictionary\n"

[root@lux2124 pipes]# 

Sam Pipe

unread,
Jul 20, 2015, 8:23:02 PM7/20/15
to salt-...@googlegroups.com
Just going a little further, salt seems to think I'm passing in a list.  I'm printing out the __class__.__name__ after the exception.  All good if you can't assist, just thought I would see if you have hit the same errors in your work.

data struct to send
{'mods': 'orchestrate.update-tomcats', 'tgt': '*', 'pillar': {'env_name': 'bat', 'app_name': 'demo'}, 'expr_form': 'glob', 'client': 'runner', 'fun': 'state.orchestrate'}

type of data['pillar']
<type 'dict'>
return:
- "Exception occurred in runner state.orchestrate: Traceback (most recent call last):\n\
  \  File \"/usr/lib/python2.7/site-packages/salt/client/mixins.py\", line 317, in\
  \ low\n    data['return'] = self.functions[fun](*args, **kwargs)\n  File \"/usr/lib/python2.7/site-packages/salt/runners/state.py\"\
  , line 106, in orchestrate\n    'Pillar data must be formatted as a dictionary'+t\n\
  SaltInvocationError: Pillar data must be formatted as a dictionarylist\n"

Sam Pipe

unread,
Jul 20, 2015, 11:45:34 PM7/20/15
to salt-...@googlegroups.com
Hey mate.. 

I've worked it out.. seems I was using a data input in yaml form... This must not work exactly correctly and then converts the pillar into a list instead of a dict.  I changed my post data to json and added the content-type json header and it triggered the orchestration.. ;-) 

Thanks for the pointer !  hugely appreciated.

Sam
Reply all
Reply to author
Forward
0 new messages