Running orchestrator through API

80 views
Skip to first unread message

Mohammad H. Al Shami

unread,
Feb 19, 2016, 2:44:39 PM2/19/16
to salt-...@googlegroups.com

Hi guys,

 

I’ve set up salt-api and can run tasks like test.ping, but how can I run something like this through API

 

salt-run state.orchestrate copy.database pillar='{"websites": ["example.com"]}'

 

I’m trying to build a web interface to automate this task

Mohammad Al Shami.vcf

Seth House

unread,
Feb 19, 2016, 6:32:44 PM2/19/16
to salt users list
It's best to send JSON when you're passing a complex data structure
(like with Pillar). Note, the payload must be an array of dictionaries
(because you can send more than one command if you want to).

% curl -b /tmp/cookies.txt \
-sSi localhost:8000 \
-H 'Content-Type: application/json' \
-d '
[{
"client": "runner",
"fun": "state.orchestrate",
"mods": "copy.database",
"pillar": {
"websites": ["example.com"]
}
}]
'

Seth House

unread,
Feb 19, 2016, 6:42:41 PM2/19/16
to salt users list
One other note: since Orchestrate often runs things that take a while,
you may find it better to use the `runner_async` client instead.

You can poll for job returns or you can watch Salt's event bus to see
when Orchestrate completes. You can even fire custom events throughout
the Orchestrate run to send status updates during the run.

If your web interface is in JavaScript you can watch the stream
without installing any libraries: new EventSource('/events');

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#salt.netapi.rest_cherrypy.app.Events.GET

Martin Höfling

unread,
Feb 20, 2016, 2:45:06 AM2/20/16
to salt-...@googlegroups.com
On 17.02.16 07:55, Mohammad H. Al Shami wrote:
>
> I’m trying to build a web interface to automate this task
>

Not sure what kind of web interface you're aiming at but Molten can be
used to start runner jobs sync and async. You just have to select the
runner client in the dropdown instead of local one.


https://github.com/martinhoefling/molten

Best wishes

Martin
Reply all
Reply to author
Forward
0 new messages