- Update the group_vars/all.yml file with the following BGP information:
bgp_topo:
rr: mxp01
af:
- inet
- inet-vpn
- For each node within our Ansible inventory, we create a file called bgp.yml under the host_vars directory. This file holds the BGP information and BGP peers for each node. This is the example for the mxpe01 device:
$ cat host_vars/mxpe01/bgp.yml
bgp_asn: 65400
bgp_peers:
- local_as: 65400
peer: 10.100.1.254
remote_as: 65400
- Create a new Jinja2 file, bgp.j2, under the templates/junos directory, with the following data:
$ cat roles/build_router_config/templates/junos/bgp.j2
protocols {
{% if bgp_peers is defined %}
bgp {
group Core {
type internal;
local-address {{ lo_ip[inventory_hostname] | ipaddr('address')}};
{% if bgp_topo.rr == inventory_hostname %}
cluster {{ lo_ip[inventory_hostname].split('/')[0] }};
{% endif %}
{% for af in bgp_topo.af %}
{% if af == 'inet' %}
family inet {
unicast;
}
{% endif %}
{% if af == 'inet-vpn' %}
family inet-vpn {
unicast;
}
{% endif %}
<-- Output Trimmed for brevity ------>
{% endfor %}
{% for p in bgp_peers %}
neighbor {{ p.peer}};
{% endfor %}
}
}
{% endif %}
}
- In the build_device_config.yml file inside the tasks folder, add the following highlighted task:
$ cat roles/build_router_config/tasks/build_device_config.yml
<-- Output Trimmed for brevity ------>
- name: "BGP Configuration"
template:
src: "{{Ansible_network_os}}/bgp.j2"
dest: "{{config_dir}}/{{ inventory_hostname }}/04_bgp.cfg"