post data using ansible uri module always get error "bad request" but it works for Postman

HI

I really need help on Ansible URI module . I am not sure whether it is a bug or not.

I have the following playbook and when I run it and I always get error "bad request, “Parameter "ip_address" is required”. But I have provided it when I sent the request. Please help me .

  • hosts: localhost

strategy: debug

tasks:

  • name: test post

uri:

url: “https://80.75.107.12/rest/v1/networks/3135/deallocateip

user: “nixu”

method: POST

password: “XXX”

validate_certs: no

force_basic_auth: yes

body: ‘{“ip_address”: “192.168.180.2”}’

body_format: json

register: result

  • debug: var=result

fatal: [localhost]: FAILED! => {

“changed”: false,

“connection”: “close”,

“content”: “{"message": "Parameter \"ip_address\" is required", "status": 400}”,

“content_length”: “66”,

“content_type”: “application/json”,

“date”: “Tue, 18 Jul 2017 15:46:24 GMT”,

“failed”: true,

“invocation”: {

“module_args”: {

“attributes”: null,

“backup”: null,

“body”: “{‘ip_address’:‘192.168.180.2’}”,

“body_format”: “json”,

“content”: null,

“creates”: null,

“delimiter”: null,

“dest”: null,

“directory_mode”: null,

“follow”: false,

“follow_redirects”: “safe”,

“force”: false,

“force_basic_auth”: true,

“group”: null,

“headers”: {

“Authorization”: “Basic bml4dTpwYXNz”,

“Content-Type”: “application/json”

},

“http_agent”: “ansible-httpget”,

“method”: “POST”,

“mode”: null,

“owner”: null,

“password”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,

“regexp”: null,

“remote_src”: null,

“removes”: null,

“return_content”: false,

“selevel”: null,

“serole”: null,

“setype”: null,

“seuser”: null,

“src”: null,

“status_code”: [

200

],

“timeout”: 30,

“unsafe_writes”: null,

“url”: “https://80.75.107.12/rest/v1/networks/3135/deallocateip”,

“url_password”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,

“url_username”: “nixu”,

“use_proxy”: true,

“user”: “nixu”,

“validate_certs”: false

}

},

“json”: {

“message”: “Parameter "ip_address" is required”,

“status”: 400

},

“msg”: “Status code was not [200]: HTTP Error 400: BAD REQUEST”,

“redirected”: false,

“server”: “nginx/1.10.1”,

“status”: 400,

“url”: “https://80.75.107.12/rest/v1/networks/3135/deallocateip

}

You’re sure it’s using POST?
Alternatively try supplying a yaml data structure for body and let ‘body_format: json’ create the json.

Can it be that the request requires additional http headers to be set?