Query prefixes once for all hosts
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).
This commit is contained in:
parent
1c0709a6a6
commit
457ab7d3b7
10 changed files with 52 additions and 50 deletions
16
roles/facts/tasks/main.yml
Normal file
16
roles/facts/tasks/main.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
# 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") }}'
|
Loading…
Add table
Add a link
Reference in a new issue