Network Automation With Ansible-Part2
Network Automation With Ansible-Part2
Ansible – Part 2
# Variable defined in xr-config/vars/main.yml # Leverages j2 template for standard and variable config
hostname {{item.hostname}}
---
service timestamps log datetime msec
router_hostname:
service timestamps debug datetime msec
- { hostname: router-rtr1, timezone: EST,
clock timezone {{item.timezone}} {{item.timezone_offset}}
timezone_dst: EDT, timezone_offset: -5 }
clock summer-time {{item.timezone_dst}} recurring
- { hostname: router-rtr2, timezone: EST,
timezone_dst: EDT, timezone_offset: -5 }
...
Jinja2 Template – For loop
• For Loop is invoked using {% for x in y %} syntax and ends with {% endfor %} syntax
# /template/template.j2
{% for interface in interface_list %}
interface {{interface}}
cost 1
!
{% endfor %}
!
# /vars/main.yml
Interface_list:
- GigabitEthernet0/0/0/0
- GigabitEthernet0/0/0/1
Hierarchical templates and Block configs
• Ansible Training
• Ansible for the Absolute Beginner @Udemy Click here
• Ansible for Network Engineers @Udemy Click here
• Kirk Byers Ansible training Jive page