Skip to content

Instantly share code, notes, and snippets.

@Slimmons
Last active June 29, 2016 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Slimmons/a6ed94db751cf57bec59519155af9ecd to your computer and use it in GitHub Desktop.
Save Slimmons/a6ed94db751cf57bec59519155af9ecd to your computer and use it in GitHub Desktop.
#This is the command I'm running to test the api
curl -H "Accept: application/json" -d tgt='*' -d secretkey="replacethiswithsomethingbetter" -k https://192.168.1.1:8080/hook/services/restart
#The return I get from this command is:
{"success": true}
#but it's not actually creating the file on the minion, like it does when I run the state alone.
#There is no error output in /var/log/salt/minion
#I know the state works because I've tested it on its own using
salt '*' state.sls reactor
#This is the tutorial I was taking this from
http://bencane.com/2014/07/17/integrating-saltstack-with-other-services-via-salt-api/
#output of salt-run state.event pretty=True
salt/netapi/hook/services/restar {
"_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": "*"
}
}
#/srv/salt/reactor/init.sls
{% set postdata = data.get('post', {}) %}
{% if postdata.secretkey == "replacethiswithsomethingbetter" %}
test:
cmd.run:
- name: touch /home/username/test.txt
- cwd: /home/username
- tgt: '{{ postdata.tgt }}'
{% endif %}
#/etc/salt/master.d/reactor.conf
reactor:
- 'salt/netapi/hook/restart':
- /srv/salt/reactor/init.sls
#/etc/salt/master.d/salt-api.conf
rest_cherrypy:
port: 8080
host: 192.168.1.1
ssl_crt: /etc/ssl/private/cert.pem
ssl_key: /etc/ssl/private/key.pem
webhook_disable_auth: True
webhook_url: /hook
#/srv/salt/top.sls
base:
'*':
- reactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment