Hi all,

I try to simplify my Nginx template by using extends template. To do that, 
I follow the Jinja2 doc 
<http://jinja.pocoo.org/docs/dev/templates/#block-nesting-and-scope>

I create a child template:
































*{% extends "nginx_servers.j2" %}{% block listen %}        listen {{ 
item.server.listen }};{% endblock %}{% block servername %}        
server_name {{ item.server.server_name }};{% endblock %}{% block root 
%}        # Root directory        root {{ item.server.root }};{% endblock 
%}{% block ssl %}        # Ssl configuration        ssl on;        
ssl_certificate {{ item.server.ssl_certificate }};        
ssl_certificate_key {{ item.server.ssl_certificate_key }};{% endblock %}{% 
block logs %}        # Logs        access_log {{ item.server.access_log 
}};        error_log {{ item.server.error_log }};{% endblock %}{% block 
location %}        location {{ loc.name }} { {% for k,v in loc 
%}                    {{ k }} {{ v }};{% endfor %}        }{% endblock %}*

Then I create my vhosts template ( nginx_servers.j2 )

















*:server {{% block listen %}{% endblock %}{% if 'server_name' in 
item.server %}{% block servername %}{% endblock %}{% endif %}{%if 'root' in 
item.server %}{% block root %}{% endblock %}{% endif %}{% if 'ssl' in 
item.server %}{% block ssl %}{% endblock %}{% endif %}{% if 'access_log' in 
item.server %}{% block logs %}{% endblock %}{% endif %}{% for loc in item 
%}{% if loc.find('location') != -1 %}{% block *




*location scoped %}{{ loc }}{% endblock %}{% endif %}{% endfor %}}*My 
variable file:












*nginx_servers:  - server:      name: "site1"      listen: 80      
server_name: "site1"      location1:        name: "/"        try_files: 
"$uri $uri/ /index.php"      location2:        name: "bla"        
auth_basic: "\"Restricted Area\""        auth_basic_user_file: 
"xxxxxxxxxxx"*
















*  - server:      name: "site2"      listen: 443      server_name: 
"site2"      location1:        name: "/"        try_files: "$uri $uri/ 
/index.php"      location2:        name: "~ \\.ini$"        deny: 
"all"      location3:        name: "~ /\\.ht"        allow: "all"}*All the 
simple block works fine ( servername, listen ... ), but when I run the 
location block, I get this error :

*fatal: [127.0.0.1] => {'msg': "KeyError: 'undefined variable: 0'", 
'failed': True}*
I try to just print loc variable in the block, but I get the same error.

Does this feature is available in Ansible ? 

Thanks.

-- 
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/abc02d61-2c00-48df-9e47-390cade13c4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to