Network Automation Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Create a new Jinja2 file, ospf.j2, in the templates/junos directory, with the following data:
$ cat roles/build_router_config/templates/junos/ospf.j2

protocols {
ospf {
area {{global.ospf_area}} {
{% for intf in p2p_ip[inventory_hostname]|sort(attribute='port') %}
interface {{ intf.port }} {
interface-type p2p;
metric {{intf.cost | default(100)}};
}
{% endfor %}
interface lo0.0 {
passive;
}
}
}
}
  1. In the junos_build_config.yml file inside the tasks folder, add the following task:
$ cat roles/build_router_config/tasks/build_device_config.yml

<-- Output Trimmed for brevity ------>

- name: "OSPF Configuration"
template:
src: "{{Ansible_network_os}}/ospf.j2"
dest: "{{config_dir}}/{{ inventory_hostname }}/02_ospf.cfg"