Timotej Lazar
457ab7d3b7
And group them into vrf_prefixes for VLAN networks and bgp_prefixes for servers plugged directly into fabric. This should reduce the number of queries to NetBox when configuring firewalls and exit switches. Not sure but I think set_fact helps to avoid queries (as opposed to setting group_vars).
17 lines
802 B
YAML
17 lines
802 B
YAML
# Make expensive lookups to NetBox once for later reference by any host.
|
|
- name: Lookup networks and prefixes
|
|
set_fact:
|
|
vlans: '{{ query("netbox.netbox.nb_lookup", "vlans", api_filter="group=new-net", raw_data=true)
|
|
| sort(attribute="vid") }}'
|
|
prefixes: '{{ query("netbox.netbox.nb_lookup", "prefixes", raw_data=true)
|
|
| sort(attribute="prefix") | sort(attribute="family.value") }}'
|
|
|
|
- name: Select VLAN and BGP prefixes
|
|
set_fact:
|
|
vrf_prefixes: '{{ prefixes | selectattr("vrf")
|
|
| selectattr("vlan") | selectattr("vlan.id", "in", vlans|map(attribute="id"))
|
|
| sort(attribute="vlan.vid") }}'
|
|
bgp_prefixes: '{{ prefixes | selectattr("tenant")
|
|
| selectattr("role") | selectattr("role.slug", "==", "bgp")
|
|
| sort(attribute="tenant.slug") }}'
|