ansible 2.7, same call over curl works fine>
curl -X POST " -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"hostname\": \"string\", \"name\": \"string\", \"service\": \"string\", \"extra\": {}, \"args\": [ \"string\" ], \"module\": \"string\", \"filename\": \"string\", \"pathname\": \"string\", \"requestid\": \"string\", \"message\": \"string\", \"funcname\": \"string\", \"levelname\": \"INFO\", \"lineno\": 0}"
uri module gives me the following error:
[WARNING]: provided hosts list is empty, only localhost is available. Note 2 that the implicit localhost does not match 'all' 3 4 5 PLAY [update log via api] ****************************************************** 20:37:30 6 7 TASK [uri] ********************************************************************* 20:37:30 8 [DEPRECATION WARNING]: Supplying headers via HEADER_* is deprecated. Please use 9 headers to supply headers for the request. This feature will be removed in 10 version 2.9. Deprecation warnings can be disabled by setting 11 deprecation_warnings=False in ansible.cfg. 12 fatal: [localhost]: FAILED! => {"access_control_allow_origin": "*", "changed": false, "connection": "Upgrade, close", "content": "{\"message\": \"Input payload validation failed\", \"errors\": {\"\": \"u'{\n \"hostname\": \"string\",\n \"name\": \"string\",\n \"service\": \"string\",\n \"extra\": {},\n \"args\": [\n \"string\"\n ],\n \"module\": \"string\",\n \"filename\": \"string\",\n \"pathname\": \"string\",\n \"requestid\": \"string\",\n \"message\": \"string\",\n \"funcname\": \"string\",\n \"levelname\": \"INFO\",\n \"lineno\": 0\n}' is not of type u'object'\"}}\n", "content_length": "469", "content_type": "application/json", "date": "Thu, 30 May 2019 01:37:35 GMT", "json": {"errors": {"": "u'{\n \"hostname\": \"string\",\n \"name\": \"string\",\n \"service\": \"string\",\n \"extra\": {},\n \"args\": [\n \"string\"\n ],\… 13 14 PLAY RECAP ********************************************************************* 20:37:37 15 localhost : ok=0 changed=0 unreachable=0 failed=1
---
- hosts: localhost
name: update log via api
gather_facts: false
vars_files:
vars.yml
vars:
tasks:
- uri:
url: "{{ api_log_url }}"
method: POST
force_basic_auth: yes
url_username: "{{ api_log_user }}"
url_password: "{{ api_log_password }}"
body_format: json
return_content: yes
HEADER_Content-Type: "application/json"
validate_certs: false
body: "{{ lookup('file','create_body.json') | to_json }}"
create_body.json:
{
"hostname": "string",
"name": "string",
"service": "string",
"extra": {},
"args": [
"string"
],
"module": "string",
"filename": "string",
"pathname": "string",
"requestid": "string",
"message": "string",
"funcname": "string",
"levelname": "INFO",
"lineno": 0
}
curl
body since the entire payload is literal:-d '{"hostname": "string", etc etc}'
– mdaniel