FWIW jinja2/template includes are working for me in 1.5 with a few notes;

  + context is automatically inherited, no need to pass with context

  + {% include filename %} only accepts relative paths for filename. eg.
    - {% include "inc/filename.j2" %} works,
    - {% include "/etc/ansible/templates/inc/filename.j2" %} does not


Here's an example;

Main template;
https://github.com/iceburg-net/ansible-pcd/blob/master/roles/applications/apache_sites/templates/virtualhost_http.j2

Included template;
https://github.com/iceburg-net/ansible-pcd/blob/master/roles/applications/apache_sites/templates/includes/wordpress-3.j2

[ ps the pcd project is in an embarrassing state && needs a reorg/refactor 
:) ] 



On Tuesday, April 15, 2014 4:09:12 PM UTC-5, Michael DeHaan wrote:
>
> Yep, this is a known thing, Jinja2 includes (however those work) aren't 
> well tolerated in Ansible right now. 
>
> History in github indicates these used to work -- so I'd welcome a ticket. 
>    A pull request to add them would be even better.  
>
> (They are not very widely used/wanted at all, so it may take a while to 
> get to this).
>
>
>
> On Fri, Apr 11, 2014 at 6:05 AM, Thomas Klein <[email protected]<javascript:>
> > wrote:
>
>> Hi,
>>
>> i'm working with ansible 1.5 and encounter a problem when working with 
>> includes in templates.
>>
>> In one template file i have this code snippet:
>> {% for group in group_names %}
>>     {% include "debug_include.j2" with context %}
>> {% endfor %}
>>
>> In the included template 'debug_include.j2' i have this code:
>> This is the included Template. The current group is {{group}}
>>
>> The documentation claims that included templates have the same variable 
>> context as the main file.
>> So i would expect to see something like:
>> This is the included Template. The current group is mailserver
>>
>> Instead i get an error on the commandline when executing this play:
>> TASK: [common-linux | dump all variables] 
>> *************************************
>> fatal: [ltesthost] => {'msg': "One or more undefined variables: 'group' 
>> is undefined", 'failed': True}
>> fatal: [testhost] => {'msg': "One or more undefined variables: 'group' is 
>> undefined", 'failed': True}
>>
>> FATAL: all hosts have already failed -- aborting
>>
>> Did i miss somthing here ?
>>
>>
>>  -- 
>> 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/7315ede0-c95a-47ad-8788-00b81022ea89%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/7315ede0-c95a-47ad-8788-00b81022ea89%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/269db00f-bf99-42b9-bb7f-18adddcdd781%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to