Reputation: 2270
I'm trying to set up a really basic salt-api configuration just to test it out. I'm using salt-master and salt-minion 2016.3.0 Boron on Ubuntu 14.04
I'm using this tutorial, and my configuration is below.
/srv/salt/top.sls
base:
'*':
- reactor
/etc/salt/master.d/reactor.conf
reactor:
- 'salt/netapi/hook/restart':
- /srv/reactor/test.sls
/srv/reactor/test.sls
{% set postdata = data.get('post', {}) %}
{% if postdata.secretkey == "replacethiswithsomethingbetter" %}
test:
local.cmd.run:
- tgt: '{{ postdata.tgt }}'
-arg:
- touch /home/username/test.txt
{% endif %}
I have restarted the master, and if I run salt '*' state.sls reactor
then everything in the state works fine. All it does is touch /home/username/test.txt
, and that file is created when I run the state.
The command I'm running to use the API is
curl -H "Accept: application/json" -d tgt='*' -d secretkey="replacethiswithsomethingbetter" -k https://192.168.1.1:8080/hook/services/restart
and that command returns {"success": true}
Then I check on the minion, and the file hasn't been created.
The output of salt-run state.event pretty=True
is
salt/netapi/hook/services/restart {
"_stamp": "2016-06-29T19:30:04.193832",
"body": "",
"headers": {
"Accept": "application/json",
"Content-Length": "46",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "192.168.1.1:8080",
"Remote-Addr": "192.168.1.3",
"User-Agent": "curl/7.35.0"
},
"post": {
"secretkey": "replacethiswithsomethingbetter",
"tgt": "*"
}
}
I did go through all of the self signed cert steps. I'm not 100% sure why I need those, but it's done, and they are listed in the rest_cherrypy configs.
Any help is appreciated.
EDIT 1
I edited the reactor stuff, because there's an example of using cmd.run, or local.cmd.run located int he salt docs here
It's still returning true, and not working.
Upvotes: 1
Views: 496
Reputation: 4496
URL is wrong:
https://192.168.1.1:8080/hook/services/restart
should change to :
https://192.168.1.1:8080/hook/restart
because what you defined is :
reactor:
- 'salt/netapi/hook/restart':
- /srv/reactor/test.sls
You can view debug log by run salt-master as salt-master -l debug
.
Upvotes: 1