User Tools

Site Tools


automation:jinja2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
automation:jinja2 [2017/05/27 14:07] jotasandokuautomation:jinja2 [2023/11/02 14:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
 **JINYA**\\ **JINYA**\\
-It uses a template file (jinja) and a //templating code// (in python) but it might be easier to use Ansible instead of the python code (see [[https://en.wikipedia.org/wiki/Jinja_(template_engine)|External Link]]).\\+  * Nice examples: https://github.com/dgjnpr/ansible-template-for-junos 
 +  * It uses a template file (jinja) and a //templating code// (in python) but it might be easier to use Ansible instead of the python code (see [[https://en.wikipedia.org/wiki/Jinja_(template_engine)|External Link]]).\\ 
 +  * All the links plus a tutorial can be found [[http://vulgarpython.com/jinja2-templates-for-network-automation/|here]] 
 +  * Loop with variable and multiple template and targets : [[http://www.mydailytutorials.com/ansible-template-module-examples/|Link]] 
 +\\ 
 +Note that, in Ansible, ROLES are the ones that generate the configurations, **Roles are made up of a task and one or more template file**.
 \\ \\
 VARIABLE VARIABLE
Line 12: Line 17:
   {# do something here #}   {# do something here #}
   {% endif %}   {% endif %}
 +INCLUDING CONTENT OF FILES IN THE RENDERED TEMPLATE:
 +  system{
 +    {% include "login.j2" %}
 +    {% include "services.j2" %}
 +  }
 +INCLUDING BLOCKS:\\
 +Note that this is the parent configuration, having the section inside the block 'elegible' to be overriden.
 +  services {
 +    ssh;
 +     {% block dhcp %}
 +    dhcp{
 +      pool 0.0.0.0/0;
 +    }
 +     {% endblock dhcp %}
 +  }
automation/jinja2.1495894054.txt.gz · Last modified: (external edit)