I am using salt API to run commands like cloud.list_locations using runner client. The output is perfectly accurate. My concern is with return value.
When I run the cloud.list_locations I get a list of locations with no other detail. Along with the output I want to know the return value the API call gives so that I can use it to determine whether the call was successful or not. I can then use it to update other integrated applications.
So doest salt API call give a return value? If yes how to access it?
(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)
(Include debug logs if possible and relevant.)
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
The exit code is not currently exposed by Salt's public-facing API methods. It is a newer addition and still unfinished and undocumented (see #18510), although it is still useful in it's current state and this is a recurring ask. We'll get it added.
PR above adds an initial implementation of how to expose this info.
Also looks like a start to resolve #37043
Thanks for cross-linking those issues! This turned out to be much easier than I first thought. I tested this addition from salt-api and the extra return output Just Worked (TM). We might want a convenience in salt-api somewhere to avoid having to pass the extra kwarg all the time.
@whiteinge Have your additions been merged into 2016.11 or will they be released with the upcomming 2017.xx release?
2017.xx (Nitrogen). Thanks for asking -- I forgot to add this to the upcoming release notes.
@whiteinge Can you give an example salt-api call to trigger the full_return=True functionality? In adding the bits from #39492 and then sending JSON like:
{"client":"runner","fun":"salt.cmd","arg":"test.ping","kwarg":{"full_return": "True"}}
salt-api sends back
{"return": ["Exception occurred in runner salt.cmd: Traceback (most recent call last):\n File \"/usr/lib/python2.7/dist-packages/salt/client/mixins.py\", line 395, in _low\n data['return'] = self.functionsfun\n File \"/usr/lib/python2.7/dist-packages/salt/runners/salt.py\", line 67, in cmd\n utils=utils(__opts__)).get(fun)(args, *kws)\nTypeError: ping() takes no arguments (1 given)\n"]}
While sending JSON for cmd.run, doesn't show the full_return functionality at all:
{"client":"local","tgt":"*","expr_form":"glob","fun":"cmd.run","arg":"sleep 5; ls -la","kwarg":{"full_return": "True"}}
{"return": [{"minion1": "total 20\n... root 4096 Mar 25 07:51 .ssh"}]}
The arg and kwarg values are sent to the module that is being invoked but this addition is a kwarg on the class itself so it should be top-level:
{
"client": "local",
"tgt": "*",
"expr_form": "glob",
"fun": "cmd.run",
"arg": "sleep 5; ls -la",
"full_return": "True"
}
Most helpful comment
Thanks for cross-linking those issues! This turned out to be much easier than I first thought. I tested this addition from salt-api and the extra return output Just Worked (TM). We might want a convenience in salt-api somewhere to avoid having to pass the extra kwarg all the time.