How to do it...

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

protocols {
ldp {
{% for intf in p2p_ip[inventory_hostname]|sort(attribute='port') %}
interface {{intf.port}}.{{intf.vlan|default('0')}};
{% endfor %}
interface lo0.0;
}
rsvp {
{% for intf in p2p_ip[inventory_hostname]|sort(attribute='port') %}
interface {{intf.port}}.{{intf.vlan|default('0')}};
{% endfor %}
}
mpls {
{% for intf in p2p_ip[inventory_hostname]|sort(attribute='port') %}
interface {{intf.port}}.{{intf.vlan|default('0')}};
{% endfor %}
}
}
  1. In the build_device_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: "MPLS Configuration"
template:
src: "{{Ansible_network_os}}/mpls.j2"
dest: "{{config_dir}}/{{ inventory_hostname }}/03_mpls.cfg"