How to get vars to evaluate inside json strings?

47 views
Skip to first unread message

David Reagan

unread,
Apr 15, 2015, 2:36:13 PM4/15/15
to ansible...@googlegroups.com
See 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
Reply all
Reply to author
Forward
0 new messages