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

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

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

Thanks.

[playbook:

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

sorry, this means a bug ?

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 :slight_smile:

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.

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.

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”]}}}

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 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’]}’ 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\“}”, “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”’

Playbook :