On 15.03.2019 23:55, bikram40 wrote:
> I defined a json variable in vars section and want to pass it as body in
> curl command as below:

As Sudheer mention you should take a look at the uri module.


> 
> vars:
> 
>     - paydata: {"status":"complete","message":"successfully
> 
>                 completed","actions":["close ticket"]}

This is not json in Ansible it's a dict.


> - local_action: command curl -X PUT -i -H "Content-Type:application/json"
> https://ansibledev.corp.xxxx.com:8443/api/job/{{ ticket }} -k --data "{{
> paydata }}" completed","actions":["close ticket"]}' --header
> 
> 
> 
> But here is the error I am getting. Seems "paydata" is not passed as
> expected.
> 
> 
> fatal: [10.225.240.39 -> localhost]: FAILED! => {"changed": true, "cmd":
> ["curl", "-X", "PUT", "-i", "-H", "Content-Type:application/json", "
> https://gns-ansible-dev.corp.xxx.com:8443/api/job/CRQmattcheng22";, "-k",
> "-d", "{ustatus:", "ucomplete,", "umessage:", "usuccessfully completed,",
> "uactions:", "[uclose ticket]}",

To make a dict to be formated as json you need to use the to_json filter
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data


-- 
Kai Stian Olstad

-- 
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/a096b6cb-4b69-6420-2050-057b98addb1b%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to