# How to get vars to evaluate inside json strings?

**URL:** <https://forum.ansible.com/t/how-to-get-vars-to-evaluate-inside-json-strings/17985>\
**Category:** Ansible Project\
**Created:** [April 15, 2015, 6:36pm UTC](https://forum.ansible.com/t/how-to-get-vars-to-evaluate-inside-json-strings/17985 "2015-04-15T18:36:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Reagan](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@David\_Reagan](https://forum.ansible.com/u/David_Reagan)\
**Post date:** [April 15, 2015, 6:36pm UTC](https://forum.ansible.com/t/how-to-get-vars-to-evaluate-inside-json-strings/17985/1 "2015-04-15T18:36:13Z")

</div>

See [http://pastebin.com/QWSu641w](http://pastebin.com/QWSu641w) for the testing playbook I’ve been using.

Basically, I have several vars that I need to place inside a json string.

The output should look something like:

{“indices”: “testlogstash-2014.04.14”,“ignore\_unavailable”: “true”,“include\_global\_state”: false,“partial”: true}

Vars are not evaluated unless you use double quotes, and if I use single quotes, like ‘indices’, the json is invalid. Which means I should escape the appropriate double quotes. Unfortunately, ansible still returns a syntax error.

> ERROR: Syntax Error while loading YAML script, apply.yml  
> Note: The error may actually appear before this position: line 16, column 29
> 
> - name: debug stuff  
> debug: msg=“{"indices": "{{ esmaintenance\_indexPrefix }}{{ yesterday.stdout }}","ignore\_unavailable": true,"include\_global\_state": false,"partial": true}”  
> ^  
> We could be wrong, but this one looks like it might be an issue with  
> missing quotes. Always quote template expression brackets when they  
> start a value. For instance:  
> with\_items:
> - {{ foo }}  
> Should be written as:  
> with\_items:
> - “{{ foo }}”

So, I’m rather stuck…

Any suggestions?

ansible --version  
ansible 2.0.0 (devel a0def30c34) last updated 2015/04/15 11:32:13 (GMT -700)  
lib/ansible/modules/core: (detached HEAD a19fa6ba48) last updated 2015/04/15 11:32:18 (GMT -700)  
lib/ansible/modules/extras: (detached HEAD df7fcc90d9) last updated 2015/04/15 11:32:18 (GMT -700)  
v2/ansible/modules/core: (detached HEAD 34784b7a61) last updated 2015/03/05 16:10:19 (GMT -700)  
v2/ansible/modules/extras: (detached HEAD df7fcc90d9) last updated 2015/04/15 11:32:18 (GMT -700)  
configured module search path = None
