Hello,
I have a WebService that I need to connect to and add content via POST
method. It accepts content in the form of
"application/x-www-form-urlencoded". I am using JSON formatted body and I
tell Ansible to use form-urlencoded body format. I do not get any error,
the response code is 200, but the content does not get posted to the
WebService. Meanwhile, I use the exact same JSON file in a Postman
software, again I set it to use form-urlencoded format. and the Postman
posts the content to the WebService fine. I am missing something in Ansible
and I cannot figure out what. Can you please help?
[root@ansible ~]# python --version
Python 2.7.5
[root@ansible ~]#
[root@ansible ~]# ansible --version --quiet
ansible 2.7.5
*Here is my play:*
- name: Sample Task
local_action:
module: uri
url: <the correct URL>
method: POST
headers:
Content-Type: "application/x-www-form-urlencoded"
body_format: json
body: "{{ lookup('file','/tmp/outage.json') }}"
use_proxy: no
validate_certs: no
timeout: 300
*Here is my JSON file:*
param={
"Username": "*****",
"Password": "******",
"MessageInfo": {
"messageId": "",
"messageType": "Some Type",
"category": "Some Category",
"message": "Message to be added to the WebService",
"recurrenceFlag": "0",
"indCode": "",
"requestor": "",
"implementer": "",
"ticketNumber": "Ticke tnumber",
"systemList": [
{
"systemId": "",
"systemName": "The system the message should be added to",
"ucmdbCiId": ""
}
],
"instanceList": [],
"schedule": {
"tzName": "(GMT+01:00) Amsterdam, Berlin, Bern, Rome,
Stockholm, Vienna",
"startDate": "25.03.2019 00:30",
"endDate": "25.03.2019 04:15",
"startDay": null,
"endDay": null,
"startTime": null,
"duration": null,
"weeklyDays": null,
"monthlyDay": null
}
}
}
*Here is the Ansible output:*
TASK [pre_patching : Sample Task]
****************************************************************************************************************************************************************
.
.
ok: [127.0.0.5 -> localhost] => {
"access_control_allow_headers": "Origin, X-Requested-With,
Content-Type, Accept, LastModified, Authorization",
"access_control_allow_methods": "GET, POST, HEAD, PUT, DELETE",
"access_control_allow_origin": "*",
"access_control_max_age": "3600",
"changed": false,
"connection": "close",
"content_length": "103",
"content_type": "application/json;charset=utf-8",
"cookies": {
"JSESSIONID": "6704FFEF9C430A10794FB83A0B9F4533"
},
"cookies_string": "JSESSIONID=6704FFEF9C430A10794FB83A0B9F4533",
"date": "Wed, 02 Jan 2019 15:29:08 GMT",
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"body": "param={\n \"Username\": \"*****\",\n
\"Password\": \"*****\",\n \"MessageInfo\": {\n \"messageId\":
\"\",\n \"messageType\": \"Some Type\",\ \"category\": \"Some
Category\",\n \"message\": \"Message to be added to the
WebService\",\n \"recurrenceFlag\": \"0\",\n \"indCode\":
\"\",\n \"requestor\": \"\,\n \"implementer\": \"\",\n
\"ticketNumber\": \"Ticke tnumber\",\n \"systemList\": [\n
{\n \"systemId\": \"\",\n \"systemName\":
\"The system the message should be added to\",\n
\"ucmdbCiId\": \"\"\n }\n ],\n \"instanceList\":
[],\n \"schedule\": {\n \"tzName\": \"(GMT+01:00)
Amsterdam, Berlin, Ber, Rome, Stockholm, Vienna\",\n
\"startDate\": \"25.03.2019 00:30\",\n \"endDate\": \"25.03.2019
04:15\",\n \"startDay\": null,\n \"endDay\": null,\n
\"startTime\": null,\n \"duration\": null,\n
\"weeklyDays\": null,\n \"monthlyDay\": null\n }\n
}\n}",
"body_format": "json",
"client_cert": null,
"client_key": null,
"content": null,
"creates": null,
"delimiter": null,
"dest": null,
"directory_mode": null,
"follow": false,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"http_agent": "ansible-httpget",
"method": "POST",
"mode": null,
"owner": null,
"regexp": null,
"remote_src": null,
"removes": null,
"return_content": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 300,
"unsafe_writes": null,
"url": "<the correct URL>",
"url_password": null,
"url_username": null,
"use_proxy": false,
"validate_certs": false
}
},
"msg": "OK (103 bytes)",
"redirected": false,
"server": "Apache-Coyote/1.1",
"set_cookie": "JSESSIONID=6704FFEF9C430A10794FB83A0B9F4533; Path=/esl/;
Secure; HttpOnly",
"status": 200,
"url": "<the correct URL>"
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/defd9a05-6f23-4a80-95d1-16398ba7a643%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.