My playbook is as follows:
---
- hosts: splunk
tasks:
- uri:
url: https://localhost:8089/services/authentication/users
follow_redirects: all
method: POST
return_content: yes
timeout: 5
status_code: 400,404,500,-1
body_format: json
body: "{{ lookup('file','user.json') }}"
user: admin
validate_certs: no
password: NotMyPassword
register: X
- debug: msg="{{ X.status }}"
With supporting users file being:
{ "user": "brent", "password": "nowayposted", "roles": [ "admin","user" ] }
When I run it I get the following:
local[~/git/splunk-build] $ ansible-playbook -i "splunk," -u root post.yml
PLAY [splunk] ***************************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************************************************
ok: [splunk]
TASK [uri] ******************************************************************************************************************************************************************************************************************************************
ok: [splunk]
TASK [debug] ****************************************************************************************************************************************************************************************************************************************
ok: [splunk] => {
"msg": {
"cache_control": "no-store, no-cache, must-revalidate, max-age=0",
"changed": false,
"connection": "Close",
"content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n <messages>\n <msg type=\"ERROR\">Cannot perform action \"POST\" without a target name to act on.</msg>\n </messages>\n</response>\n",
"content_length": "179",
"content_type": "text/xml; charset=UTF-8",
"date": "Sat, 21 Apr 2018 00:02:22 GMT",
"expires": "Thu, 26 Oct 1978 00:00:00 GMT",
"failed": false,
"msg": "HTTP Error 400: Bad Request",
"redirected": false,
"server": "Splunkd",
"status": 400,
"url": "https://localhost:8089/services/authentication/users",
"vary": "Cookie, Authorization",
"x_content_type_options": "nosniff",
"x_frame_options": "SAMEORIGIN"
}
}
PLAY RECAP ******************************************************************************************************************************************************************************************************************************************
splunk : ok=3 changed=0 unreachable=0 failed=0
I also approched it by going to the REST API directly and it does not seem to accept JSON as body input. So until I can get that to work I doubt Ansible will be able to do this.
There is a whole other way to just use the command ansible module and call curl... Not for the purist though but it works like a charm.
... View more