# New problem with uri module, looks like is not parsing variables correctly :(

**URL:** <https://forum.ansible.com/t/new-problem-with-uri-module-looks-like-is-not-parsing-variables-correctly/14009>\
**Category:** Ansible Project\
**Created:** [November 26, 2013, 10:50pm UTC](https://forum.ansible.com/t/new-problem-with-uri-module-looks-like-is-not-parsing-variables-correctly/14009 "2013-11-26T22:50:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PePe\_Amengual](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PePe\_Amengual](https://forum.ansible.com/u/PePe_Amengual)\
**Post date:** [November 26, 2013, 10:50pm UTC](https://forum.ansible.com/t/new-problem-with-uri-module-looks-like-is-not-parsing-variables-correctly/14009/1 "2013-11-26T22:50:14Z")

</div>

Here is the info:

I’m trying to send a json object to akamai with the uri module but it fails saying that is not a valid json object but the debug message shows in the right format.

here is the requeriments from akamai : [https://api.ccu.akamai.com/ccu/v2/docs/index.html#section\_OtherInterfaces](https://api.ccu.akamai.com/ccu/v2/docs/index.html#section_OtherInterfaces)

Any ideas whi uri module changes from double quotes to single quotes ?

Thanks.

[playbook:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 26, 2013, 11:56pm UTC](https://forum.ansible.com/t/new-problem-with-uri-module-looks-like-is-not-parsing-variables-correctly/14009/2 "2013-11-26T23:56:20Z")

</div>

This conclusion that there is something wrong with variable parsing is incorrect because the variable parsing is quite generic.

---

<div class="post-metadata">

**Author:** ![PePe\_Amengual](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PePe\_Amengual](https://forum.ansible.com/u/PePe_Amengual)\
**Post date:** [November 27, 2013, 12:21am UTC](https://forum.ansible.com/t/new-problem-with-uri-module-looks-like-is-not-parsing-variables-correctly/14009/3 "2013-11-27T00:21:02Z")

</div>

sorry, this means a bug ?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 27, 2013, 3:16am UTC](https://forum.ansible.com/t/new-problem-with-uri-module-looks-like-is-not-parsing-variables-correctly/14009/4 "2013-11-27T03:16:21Z")

</div>

Nope, this means it’s much better to ask “what’s wrong here, how might I do this”, than to jump in and say there’s a bug in a particular module at the first sign of trouble 🙂

It looks like your data structure is set quite correctly, but I’d probably start with {{ urls | to\_json }} in the body for starters and debug from there.

---

<div class="post-metadata">

**Author:** ![PePe\_Amengual](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PePe\_Amengual](https://forum.ansible.com/u/PePe_Amengual)\
**Post date:** [November 27, 2013, 5:43pm UTC](https://forum.ansible.com/t/new-problem-with-uri-module-looks-like-is-not-parsing-variables-correctly/14009/5 "2013-11-27T17:43:48Z")

</div>

Understand your point, I was getting carried away since I found I bug in the URI module already :).

I wrote a bash script already to solve this issue because going back and forth on debugging takes time and I need this done today.

Since I still have the playbook I will try it again and debug to see if the problem goes away but I think I was using the wrong tool for the job.

---

<div class="post-metadata">

**Author:** ![PePe\_Amengual](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PePe\_Amengual](https://forum.ansible.com/u/PePe_Amengual)\
**Post date:** [November 27, 2013, 6:44pm UTC](https://forum.ansible.com/t/new-problem-with-uri-module-looks-like-is-not-parsing-variables-correctly/14009/6 "2013-11-27T18:44:57Z")

</div>

So I tried with to\_json:

plase look closely to the TASK: [set\_fact] that shows the right format and then look at the TASK: [Flushing Akamai cache] where it shows in single cuotes that is where the problem is!.

When using - debug: var={{ urls | to\_jason }} shows some empty string there and yes I have jinga2 installed ( using 1.4 in freebsd)

Thanks.

this is the debug :

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [set\_fact] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {“ansible\_facts”: {“urls”: {“objects”: [“[http://url/file/pepe.png](http://url/file/pepe.png)”, “[http://url/file/pepe.png](http://url/file/pepe.png)”, “[http://url/file/pepe.png](http://url/file/pepe.png)”, “[http://url/file/pepe.png](http://url/file/pepe.png)”]}}}

TASK: [debug var={{urls | to\_jason}}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“{{urls”: “{{ {{urls }}”  
}

TASK: [Flushing Akamai cache] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-1385551881.43-185813033534451 && chmod a+rx $HOME/.ansible/tmp/ansible-1385551881.43-185813033534451 && echo $HOME/.ansible/tmp/ansible-1385551881.43-185813033534451’]  
 REMOTE\_MODULE uri url=[https://api.ccu.akamai.com/ccu/v2/queues/default](https://api.ccu.akamai.com/ccu/v2/queues/default) method=POST user=aaaaaa password=aaaaa HEADER\_Content-Type=“application/json” body=‘{‘objects’: [‘[http://url/file/pepe.png](http://url/file/pepe.png)’, ‘[http://url/file/pepe.png](http://url/file/pepe.png)’, ‘[http://url/file/pepe.png](http://url/file/pepe.png)’, ‘[http://url/file/pepe.png’]}’](http://url/file/pepe.png'%5D%7D') status\_code=201 return\_content=yes  
 PUT /tmp/tmp\_lboPi TO /usr/home/jamengual/.ansible/tmp/ansible-1385551881.43-185813033534451/uri  
 EXEC [’/bin/sh’, ‘-c’, ‘/usr/local/bin/python /usr/home/jamengual/.ansible/tmp/ansible-1385551881.43-185813033534451/uri; rm -rf /usr/home/jamengual/.ansible/tmp/ansible-1385551881.43-185813033534451/ \>/dev/null 2\>&1’]  
failed: [localhost] =\> {“allow”: “GET, HEAD, POST”, “connection”: “close”, “content”: "{"title": "bad request", "httpStatus": 400, "detail": "Invalid JSON document", "describedBy": "[https://api.ccu.akamai.com/ccu/v2/errors/bad-request\“}”](https://api.ccu.akamai.com/ccu/v2/errors/bad-request%5C%22%7D%22), “content\_length”: “149”, “content\_type”: “application/api-problem+json”, “date”: “Wed, 27 Nov 2013 18:38:35 GMT”, “failed”: true, “redirected”: false, “server”: “Apache”, “status”: 400, “vary”: “Authorization”}  
msg: Status code was not 201

FATAL: all hosts have already failed – aborting

running ansible like this :

ansible-playbook -vvv -i /etc/ansible/hosts /home/jamengual/akamai.yml -e @args.yml

args.yml :

urllist: ‘“[http://url/file/pepe.png",“http://url/file/pepe.png”,“http://url/file/pepe.png”,"http://url/file/pepe.png](http://url/file/pepe.png%22,%22http://url/file/pepe.png%22,%22http://url/file/pepe.png%22,%22http://url/file/pepe.png)”’

Playbook :
