Timotej Lazar
82b10e8133
Ten minutes to set up and ten hours to convince Ansible to not be quite so retarded. The list2dict filter seems to be the (or another) missing piece. Now let’s rewrite everything else using it. Or not.
18 lines
896 B
YAML
18 lines
896 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") }}'
|
|
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") }}'
|