salt-api curl always returns true, does nothing

321 views
Skip to first unread message

John Simmons

unread,
Jun 28, 2017, 2:55:33 PM6/28/17
to Salt-users
salt-master: 2016.11.5 (Carbon)
salt-api: 2016.11.5 (Carbon)
salt-minion 2016.11.5 (Carbon)
cherrypy: 10.2.2

I used this tutorial to start learning salt-api.  http://bencane.com/2014/07/17/integrating-saltstack-with-other-services-via-salt-api/

and the only issue I had was that I had to update cherrypy to 10.2.2, until I started using the curl command, and it returns true every time, even if my sls file has errors.  Even though it returns true, it does nothing, and I'm not sure how to troubleshoot it.




What happens is I run the curl command, and it returns true, but does nothing, and there's no error output that I can find.  I'm just trying to restart apache2 at the moment.

Seth House

unread,
Jun 28, 2017, 9:31:15 PM6/28/17
to salt users list
The webhook interface in salt-api is a wrapper around firing a Salt
event -- it is a fire-and-forget interface and does not wait for the
Reactor to receive the event or react to it or for the command to go
out then return with the results/errors. It is best used to initiate
actions that have already been tested.

There's a lot of layers between those two operations and it's useful
to know those layers. A simple way to get started is:

1. Write an .sls file and test it from the CLI calling `salt <tgt>
state.sls <mod>` as normal.
2. Once that is working run the same job using the `--async` flag then
look up the result of the job using `salt-run jobs.lookup_jid <jid>`
(because this is what the Reactor will do).
3. Once that is working call `state.sls` in the same way but from a
Reactor file (same action, but in YAML syntax instead of CLI syntax),
usually using `event.send` to trigger the event (which is what the
webhook does) and with debug logging on the master to see the result
from the reactor. [1] Make sure you can look up the result of the job
using `salt-run jobs.list_jobs` / `salt-run jobs.lookup_jid <jid>` as
before.
4. Once that is working change the reactor to listen for the webhook event tag.

And, of course, if you have any other questions as you go be sure to
ask on this list. :-)

[1] https://docs.saltstack.com/en/latest/topics/reactor/index.html#debugging-the-reactor

John Simmons

unread,
Jun 28, 2017, 10:32:32 PM6/28/17
to Salt-users, se...@eseth.com
Fantastic information.  Thanks, for helping me out.  Hopefully I'll have a better grasp on it after that, and won't have any more questions :)  But if I do I'll definitely respond here.  Thanks again.

John Simmons

unread,
Jun 29, 2017, 11:32:24 AM6/29/17
to salt-...@googlegroups.com
Thanks again for the help.  I've been able to follow your instructions, and I've found that the data I'm looking for is output during the salt-master debug.  

[DEBUG   ] Sending event: tag = salt/job/201706909481110469/ret/Win7-Minion; data = {'fun_args': ['move C:\\test1.txt C:\\testdir'], 'jid': '20170629098411049', 'return': '        1 file(s) moved.', 'retcode': 0, 'success': True, 'cmd': '_return', '_stamp': '2017-06-29T14:48:42.394159', 'fun': 'cmd.run', 'id': 'PECK-Win7-Minion1'}

It appears that the data is in a list named "data", and the value I'd like to return is the retcode, or the return.  I've been trying to find anything on how to change what the reactor is listening to, but I can't find any information on that.  I've read all of the saltstack reactor docs (that I can find) including the official docs [here](https://docs.saltstack.com/en/latest/topics/reactor/).  I've also scoured through the master config file at /etc/salt/master, but I haven't actually found anything useful yet.  Can you point me in the right direction on how to change the output from the reactor once I know what output I'm needing?

--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/W0nmrErdfww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/CABsXarExTW%2BMFETJq7m%3DKgLY5on1r2rk2XFtUxg8unw%3DYask7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Seth House

unread,
Jun 29, 2017, 3:38:15 PM6/29/17
to salt users list
The Reactor listens for event tags, in this case probably something
like: `salt/job/*/ret/*` (globbing on the JID and minion ID segments).

The event data is available to Reactor SLS files as the Jinja variable
`{{ data }}` so you should be able to reference those values via `{{
data.jid }}` and `{{ data.return }}`.

But!...one thing to watch out for is if you set up the Reactor to
listen for _job return_ events, then use the Reactor to create new
jobs which create new job return events you'll have a loop which will
fill up your available disk space pretty quick. :-)

From your initial post, it sounds like you're wanting to use a webhook
to create a new job in which case you'll want to listen for a
different event tag. Something like `salt/netapi/hook/<something>`
instead.

John Simmons

unread,
Jun 30, 2017, 10:15:27 AM6/30/17
to Salt-users, se...@eseth.com
My final goal is to have a program in C# that can call the salt-api on the master using curl, and tell it to do things to the minions (all of which currently works).  My issue is that from my C# app's perspective when I call the curl command, whether it succeeds on the minion or not, it returns 'True'.  Which is the "success" value from data.  So, I think I could work out from your help, how to get the different values from data to run some logic in the SLS files using the Jinja variables.  The issue is, that I have no idea how to have the actual api call return something other than 'True'.  Sorry if I'm not explaining the problem well, or not understanding what you're saying.  

John Simmons

unread,
Jun 30, 2017, 10:23:06 AM6/30/17
to Salt-users, se...@eseth.com
Ok, it looks like I started googling the correct thing, and it looks like it isn't possible yet.


That's kind of a bummer, since it means salt-api won't be useful for what I'm trying to do.
Reply all
Reply to author
Forward
0 new messages