Can't render JSON via lookup and POST via uri module

Hi, all. I opened a ticket about this but was redirected here.

Basically, I’m having an issue where using lookup to render a template that gets passed into the uri module’s body parameter does not work. It throws an TypeError: unhashable type error.

Here’s the task I’m running:

  • name: Post
    uri:
    url: https://hooks.slack.com/endpoint
    method: POST
    return_content: no
    HEADER_Content-Type: “application/json”
    body: “{{ lookup(‘template’, ‘…/templates/my.json.j2’, convert_data=False) }}”

with this in my.json.j2:

{
“channel”: “chatops”,
“username”: “Deploy”,
“text”: “TEST Deploy!”
}

Folding the JSON into a single line within the template has the same effect. Piping the lookup response through to_json also does not work. Taking the folded JSON and using it directly in the play does work, however.

For context, this is Ansible 1.9.4 running on OSX 10.11.1. Thanks!

First of all, there is no need to use the template function here,
there is just pure json not a jinja2 template that generates json, the
'file' lookup should work just fine.

As per the module docs, the default format is raw, it seems you should
be set body_type to json.

Also what version of ansible are you using? the json format is only
recently supported.