Thanks for the help Toshio, i have verified that using the template lookup 
does exactly what I want!

To help others, also note that the path to the template is relative to the 
location of the task file that invoked it.

/Pär

I believe that using the template lookup instead of the file lookup is 
> what you want.  So something like: 
>
>    body: "{{ lookup('template', 
> 'roles/grafana/templates/datasource.json.js') }}" 
>
> -Toshio 
>
> On Tue, Sep 22, 2015 at 11:38 AM, Pär Svensson <[email protected] 
> <javascript:>> wrote: 
> > Hello! 
> > 
> > I'm trying to make a task that uses a REST api to do some final 
> > configuration of a previously installed component. 
> > I want to make a POST request with a body that is a template that uses 
> host 
> > specific variables. 
> > 
> > The closest i've come up with is the following: 
> > 
> > - name: Adding datasource via http api 
> >   uri: 
> >     url: http://{{ inventory_hostname }}:3000/api/datasources 
> >     method: POST 
> >     body_format: json 
> >     HEADER_Content-Type: "application/json" 
> >     body: "{{ lookup('file' , 
> 'roles/grafana/templates/datasource.json.j2') 
> > }}" 
> > 
> > which sends the template-file as body, but unfortunately without any 
> > variables substituted... 
> > 
> > Any idea how i should approach the problem? 
> > 
> > -- 
> > 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] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/43016a1f-b11b-4e7a-bc11-c6358185f677%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/039d0ce9-f576-4389-a965-42db7ccc3e09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to