BGP neighbor's Variable Substitution #1052
-
Let's say you have the following in uplink1: 128.66.0.2/31
uplink2: 128.66.1.2/31
uplink3: 128.66.2.2./31
uplink4: 128.66.3.2/31 And so on and so forth. For every uplink you have been given, your remote end is using the first IP address in the block and you've been given the second. Now, it's time to configure your BGP neighbors using the Now, previously you had code that used https://github.com/ansible-collections/arista.eos/blob/main/docs/arista.eos.eos_bgp_global_module.rst - so you were able to do a couple neat little tricks to reduce the amount of variables you're carrying around bgp_neighbors:
- peer: "{{ uplink1 | ansible.netcommon.ipmath(-1) }}"
remote_as: "{{ upstream_asn }}"
- peer: "{{ uplink2 | ansible.netcommon.ipmath(-1) }}"
remote_as: "{{ upstream_asn }}" The point being, that the YAML schema used an array for all the bgp neighbors, with each neighbor being a dictionary, and a It is not possible with Ansible-AVD to do something similar, since each BGP neighbor is a dictionary in YAML, with each key in the dictionary being the IP address, which is not valid YAML and Ansible does not substitute the Jinja2 expression router_bgp:
as: "{{ our_asn }}"
neighbors:
"{{ uplink1 | ansible.netcommon.ipmath(-1) }}":
remote_as: "{{ upstream_asn }}" This results in an invalid config
|
Beta Was this translation helpful? Give feedback.
Replies: 11 comments
-
@carlbuchmann Any thoughts behind using the peer as the key vs listing the peers and making it a value? |
Beta Was this translation helpful? Give feedback.
-
@sc68cal - Thank you for providing feedback on the data model. Just to clarify, what is not valid YAML schema is using a jinja2 expression as the key, I believe this is what you are stating. I understand where you are coming from and what you are stating makes perfect sense when trying to consuming However, The reason we have chosen to leverage a schema with dictionary keys vs. lists are the following:
As an example of driving the underlay configuration in |
Beta Was this translation helpful? Give feedback.
-
Additionally this is the specific template that drive eBGP peering: https://github.com/aristanetworks/ansible-avd/blob/devel/ansible_collections/arista/avd/roles/eos_designs/templates/designs/l3ls-evpn/underlay/ebgp/router-bgp.j2 |
Beta Was this translation helpful? Give feedback.
-
The only design that you have documented in My hope was to just consume the |
Beta Was this translation helpful? Give feedback.
-
@sc68cal You are absolutely correct in stating that currently we only support BGP/EVPN VXLAN design in this role at this time. However, we have been in the process of refactoring this role (in fact, it used to be called eos_l3ls_evpn) in order to support various use cases and designs, notably: pure L3LS, L2LS, WAN w/MPLS/SR/LDP, etc... This is enabled by the action plugin yaml_template_to_facts (https://avd.sh/en/latest/plugins/index.html#yaml-templates-to-facts), which allow us to re-use the various template building blocks across designs. What other customers have done at this time is create their own abstraction role similar to how eos_designs function! We would be happy to discuss and understand your use case to ensure we prioritize accordingly and address any gaps! |
Beta Was this translation helpful? Give feedback.
-
That's what bothers me about the structure and design of this project. In order to get even the smallest configuration built, I have to wade through at least three layers of indirection ( What troubles me is the upper layers of abstraction. Again, it appears that while At this point I'll probably go back to the |
Beta Was this translation helpful? Give feedback.
-
@sc68cal, I'm sorry that you feel this way, and as we are working on the 3.0.0 milestone, we plan on providing more examples in this area as we support more design or how to customize/extend it to support your own! I wanted to address your comments relating to As I said, we are not forcing you to use In the end, pick which way works best for you and your team, but if you decide to go the route of AVD, we would be happy to have live sessions to answer your questions and help you be successful with automating your network! |
Beta Was this translation helpful? Give feedback.
-
@sc68cal I did a small mock up of your variables, and with some extra json conversion it can work. uplink1: 128.66.0.2/31
uplink2: 128.66.1.2/31
uplink3: 128.66.2.2/31
uplink4: 128.66.3.2/31
our_asn: 123
upstream_asn: 321
custom_structured_configuration_router_bgp:
as: "{{ our_asn }}"
neighbors: "{{ { uplink1 | ansible.netcommon.ipmath(-1) : { 'remote_as': upstream_asn },
uplink2 | ansible.netcommon.ipmath(-1) : { 'remote_as': upstream_asn },
uplink3 | ansible.netcommon.ipmath(-1) : { 'remote_as': upstream_asn },
uplink4 | ansible.netcommon.ipmath(-1) : { 'remote_as': upstream_asn } } }}" Produces this (ignore the
Could be optimized by setting a var like uplink_bgp_template:
remote_as: 321
custom_structured_configuration_router_bgp:
as: "{{ our_asn }}"
neighbors: "{{ { uplink1 | ansible.netcommon.ipmath(-1) : uplink_bgp_template,
uplink2 | ansible.netcommon.ipmath(-1) : uplink_bgp_template,
uplink3 | ansible.netcommon.ipmath(-1) : uplink_bgp_template,
uplink4 | ansible.netcommon.ipmath(-1) : uplink_bgp_template } }}" |
Beta Was this translation helpful? Give feedback.
-
@ClausHolbechArista thank you for the example. We've done something similar to that for a different set of Ansible automation with different devices, but it was implemented poorly and was awful to look at and read, so as a general rule we avoid doing the JSON-> YAML conversion trick. Your style is more compact and concise, so this is certainly something to look at further. |
Beta Was this translation helpful? Give feedback.
-
@sc68cal - I closed the issue, and converted this to a discussion, as we will not be converting the data model for router_bgp. |
Beta Was this translation helpful? Give feedback.
-
@sc68cal - We have now updated all our data models to be a list of dictionaries in AVD 4.0.0, and fully enforced by a schema! References:
|
Beta Was this translation helpful? Give feedback.
@sc68cal - We have now updated all our data models to be a list of dictionaries in AVD 4.0.0, and fully enforced by a schema!
References:
router_bgp
: https://avd.arista.com/4.1/roles/eos_cli_config_gen/docs/input-variables.html#router-bgp