# Passing a list to a callback - quoting issue

**URL:** <https://forum.ansible.com/t/passing-a-list-to-a-callback-quoting-issue/25800>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [October 21, 2017, 3:22pm UTC](https://forum.ansible.com/t/passing-a-list-to-a-callback-quoting-issue/25800 "2017-10-21T15:22:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wildfan](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@wildfan](https://forum.ansible.com/u/wildfan)\
**Post date:** [October 21, 2017, 3:22pm UTC](https://forum.ansible.com/t/passing-a-list-to-a-callback-quoting-issue/25800/1 "2017-10-21T15:22:55Z")

</div>

I have wasted way too much time on this seemingly simple solution, and was looking for some help.

We have a Tower job to deploy AWS cloudwatch and configure the logs to monitor that is kicked off via a callback. I use the following curl-

The callback is:

`curl -f -k -H 'Content-Type: application/json' -XPOST -d '{"host_config_key": "xxxxx", "extra_vars": "{\"logs\":{{ eck_logs }},\"env_stage\":\"dev\"}"}' "https://tower.xxxx.net:443/api/v1/job_templates/xx/callback/"`

Which expands to

`"curl -f -k -H 'Content-Type: application/json' -XPOST -d '{\"host_config_key\": \"xxx\", \"extra_vars\": \"{\\\"logs\\\":\\\"[{u'file': u'/apps/app1/shared/logs/catalina.out', u'group_name': u'/on-premise/app1/container'}, {u'file': u'/apps/app1/shared/logs/app1-webapp.log', u'group_name': u'/on-premise/app1-webapp/applog'}]\\\",\\\"env_stage\\\":\\\"dev\\\"}\"}' \"https://tower.xxx.net:443/api/v1/job_templates/xx/callback/\""..`

The eck\_logs variable looks like

`

“eck\_logs”: [  
{  
“file”: “/apps/app1/shared/logs/catalina.out”,  
“group\_name”: “/on-premise/app1/container”  
},  
{  
“file”: “/apps/app1/shared/logs/app1-webapp.log”,  
“group\_name”: “/on-premise/app1/applog”  
}  
]

`

The issue i am running into is, i believe all about quoting… as it is currently, it will pass the variable to the Tower job, however it tacks on the “u” for unicode to the variable resulting in:

`

logs:

- ugroup\_name: u/on-premise/app1-webapp/container  
ufile: u/apps/app1/shared/logs/catalina.out
- ugroup\_name: u/on-premise/app1/applog  
ufile: u/apps/app1/shared/logs/app1-webapp.log

`

when i quote the eck\_logs variable in the curl command, i then instead get-

command:

`  
curl -f -k -H ‘Content-Type: application/json’ -XPOST -d ‘{“host\_config\_key”: “xxx”, “extra\_vars”: “{"logs":"{{ eck\_logs }}","env\_stage":"dev"}”}’ “[https://tower.xxx.net:443/api/v1/job\_templates/xxx/callback/](https://tower.xxx.net:443/api/v1/job_templates/xxx/callback/)”

`

result

`"curl -f -k -H 'Content-Type: application/json' -XPOST -d '{\"host_config_key\": \"xxx\", \"extra_vars\": \"{\\\"logs\\\":\\\"[{u'file': u'/apps/app1/shared/logs/catalina.out', u'group_name': u'/on-premise/app1/container'}, {u'file': u'/apps/app1/shared/logs/app1-we`bapp.log’, u’group\_name’: u’/on-premise/app1-webapp/applog’}]\",\"env\_stage\":\"dev\"}"}’ "[https://tower.xxx.net:443/api/v1/job\_templates/xxx/callback/\](https://tower.xxx.net:443/api/v1/job_templates/xxx/callback/%5C)“”

Variable on Tower:

`

logs: \>-  
[{ufile: u/apps/app1/shared/logs/catalina.out, ugroup\_name:  
u/on-premise/app1/container}, {ufile:  
u/apps/app1/shared/logs/app1-webapp.log, ugroup\_name:  
u/on-premise/app1/applog}]

`

I have tried seemingly every filter, quoting, escaping I can and i can’t get the desired variable value when passing tower…

I am looking for the results in my first example for the logs variable (list), but without the leading “u” getting added to the values…

I realize this might be a mixture of a jinja/ansible question , but does anyone have any ideas on what i can try to fix this?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 21, 2017, 6:27pm UTC](https://forum.ansible.com/t/passing-a-list-to-a-callback-quoting-issue/25800/2 "2017-10-21T18:27:29Z")

</div>

You are just giving your curl command the python data structure of `eck_logs` and effectively you get a text representation of the data which includes the `u` prefix to indicate Unicode.

You likely want to do the following instead:

{{ eck\_logs|to\_json }}

To output the data in JSON format.

---

<div class="post-metadata">

**Author:** ![wildfan](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@wildfan](https://forum.ansible.com/u/wildfan)\
**Post date:** [October 21, 2017, 9:24pm UTC](https://forum.ansible.com/t/passing-a-list-to-a-callback-quoting-issue/25800/3 "2017-10-21T21:24:37Z")

</div>

Thanks for the reply… i had tried using the to\_json filter previously with no luck… ( i apologize for so much output below, but i think it is necessary to show / solve the issue)

When called with this:

`

curl -f -k -H ‘Content-Type: application/json’ -XPOST -d ‘{“host\_config\_key”: “xxx”, “extra\_vars”: “{"logs":"{{ eck\_logs | to\_json }}","env\_stage":"dev"}”}’ “[https://tower.xxx:443/api/v1/job\_templates/xxx/callback/](https://tower.xxx:443/api/v1/job_templates/xxx/callback/)”

`

Results in  
`  
curl -f -k -H ‘Content-Type: application/json’ -XPOST -d ‘{"host\_config\_key": "xxx", "extra\_vars": "{\"logs\":\"[{"file": "/apps/app1/shared/logs/catalina.out", "group\_name": "/on-premise/app1/container"}, {"file": "/apps/app1/shared/logs/app1.log", "group\_name": "/on-premise/app1-webapp/applog"}]\",\"env\_stage\":\"dev\"}"}’ "[https://tower.xxx.net:443/api/v1/job\_templates/xxx/callback/\](https://tower.xxx.net:443/api/v1/job_templates/xxx/callback/%5C)"

`

which fails on the callback  
`  
curl: (22) The requested URL returned error: 400 BAD REQUEST

`

When I remove the quoting and escape around "{{ eck\_logs | to\_json }}" it also fails with the same curl error (it is running the following)

`  
curl -f -k -H ‘Content-Type: application/json’ -XPOST -d ‘{"host\_config\_key": "xxx", "extra\_vars": "{\"logs\":[{"file": "/apps/app1/shared/logs/catalina.out", "group\_name": "/on-premise/app1/container"}, {"file": "/apps/app1/shared/logs/app1.log", "group\_name": "/on-premise/app1/applog"}],\"env\_stage\":\"dev\"}"}’ "[https://tower.xxx.net:443/api/v1/job\_templates/xx/callback/\](https://tower.xxx.net:443/api/v1/job_templates/xx/callback/%5C)"

`

It chokes as it adds the quoting around each of the fields… it needs to pass as the following for it to give me the desired results

`  
\"[{‘file’: ‘/apps/app1/shared/logs/catalina.out’, ‘group\_name’: ‘/on-premise/app1/container’}, {‘file’: ‘/apps/app1/shared/logs/app1-webapp.log’, ‘group\_name’: ‘/on-premise/app1-webapp/applog’}]\"

`

---

<div class="post-metadata">

**Author:** ![wildfan](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@wildfan](https://forum.ansible.com/u/wildfan)\
**Post date:** [October 21, 2017, 11:04pm UTC](https://forum.ansible.com/t/passing-a-list-to-a-callback-quoting-issue/25800/4 "2017-10-21T23:04:12Z")

</div>

Sorry for the additional reply, but i realized i had the incorrect desired output in my last one… When the curl command is the following, it works and gives me the correct extra-var on the tower side:

`

curl -f -k -H ‘Content-Type: application/json’ -XPOST -d ‘{“host\_config\_key”: “xxx”, “extra\_vars”: “{"logs":[{file: /apps/app1/shared/logs/catalina.out, group\_name: /on-premise/app1/container}, {file: /apps/app1/shared/logs/app1.log, group\_name: /on-premise/app1/webapp/applog}],"env\_stage":"dev"}”}’ “[https://tower.xxx.net:443/api/v1/job\_templates/xxx/callback/](https://tower.xxx.net:443/api/v1/job_templates/xxx/callback/)”

`

`

env\_stage: dev  
logs:

- file: /apps/app1/shared/logs/catalina.out  
group\_name: /on-premise/app1/container
- file: /apps/app1/shared/logs/app1.log  
group\_name: /on-premise/app1/webapp/applog

`

for it to work, the {{ eck\_logs }} variable to expand to not include the quoting (ie [{file: /apps/app1/shared/logs/catalina.out, group\_name: /on-premise/app1/container}, {file: /apps/app1/shared/logs/app1.log, group\_name: /on-premise/app1/webapp/applog}]) or the callback fails.

thx  
-T

---

<div class="post-metadata">

**Author:** ![wildfan](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@wildfan](https://forum.ansible.com/u/wildfan)\
**Post date:** [October 21, 2017, 11:34pm UTC](https://forum.ansible.com/t/passing-a-list-to-a-callback-quoting-issue/25800/5 "2017-10-21T23:34:53Z")

</div>

Thanks Matt for steering me towards a solution…I was able to get this working, utilizing the to\_json and then stripping out all quotes… I used an intermediate fact to get to the final desired output as i didnt have luck when doing it inline, but there may be a way to skip that extra step…

`

- block:
- name: Create fact for log info to format for callback  
set\_fact:  
logs: “{{ eck\_logs | to\_json | replace(‘"’, ‘’) }}”
- name: Perform callback to tower to configure ECK logging  
command: \>  
curl -f -k -H ‘Content-Type: application/json’ -XPOST -d ‘{“host\_config\_key”: “xxx”, “extra\_vars”: “{"logs":{{ logs }},"env\_stage":"dev"}”}’ “[https://tower.xxx.net:443/api/v1/job\_templates/xx/callback/](https://tower.xxx.net:443/api/v1/job_templates/xx/callback/)”  
when: eck\_logs is defined

`

thx for pointing me in the right direction, and sorry for all my replies!

-T
