So I'm able to create the dictionary, and I can convert it to JSON in a 
debug statement, but when I try to convert it to JSON in the URI module it 
throws an unhandled exception. What's going on here?

---
- name: testguy
  gather_facts: no
  sudo: no
  hosts: local

  tasks:
  - set_fact:
      stash_json: { text: "some thing" }
  - debug:
      msg: '{{ stash_json | to_json }}'
  - uri: >
      url=http://www.example.com
      method=POST
      body='{{ stash_json | to_json }}'
      return_content=yes
      HEADER_Content-Type="application/json"



$ ansible-playbook -i hosts test.yml

PLAY [test] 
**************************************************************** 

TASK: [set_fact ] 
************************************************************* 
ok: [localhost]

TASK: [debug ] 
**************************************************************** 
ok: [localhost] => {
    "msg": {
        "text": "some thing"
    }
}
Traceback (most recent call last):
  File "/tmp/jim/env/bin/ansible-playbook", line 269, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/tmp/jim/env/bin/ansible-playbook", line 209, in main
    pb.run()
  File 
"/tmp/jim/env/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", 
line 263, in run
    if not self._run_play(play):
  File 
"/tmp/jim/env/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", 
line 592, in _run_play
    if not self._run_task(play, task, False):
  File 
"/tmp/jim/env/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", 
line 357, in _run_task
    self.callbacks.on_task_start(template(play.basedir, name, 
task.module_vars, lookup_fatal=False, filter_fatal=False), is_handler)
  File 
"/tmp/jim/env/local/lib/python2.7/site-packages/ansible/utils/template.py", 
line 319, in template
    varname = template_from_string(basedir, varname, vars, 
fail_on_undefined)
  File 
"/tmp/jim/env/local/lib/python2.7/site-packages/ansible/utils/template.py", 
line 543, in template_from_string
    return res
UnboundLocalError: local variable 'res' referenced before assignment

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to