network/roles/facts/tasks/main.yml

18 lines
896 B
YAML
Raw Permalink Normal View History

# 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") }}'
vrfs: '{{ query("netbox.netbox.nb_lookup", "vrfs", raw_data=true) | list2dict("name") }}'
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") }}'