servers/roles/facts/tasks/main.yml
Timotej Lazar c7a3513fa1 Add netbox role
Kinda ouroborosish if you think about it. Better don’t.
2024-05-28 12:32:28 +02:00

19 lines
888 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: Get my cluster and all nodes in it
set_fact:
cluster: '{{ query("netbox.netbox.nb_lookup", "clusters", raw_data=true, api_filter="name="+cluster) | first }}'
nodes: '{{ groups["cluster_"+cluster] | map("extract", hostvars) | rejectattr("is_virtual") }}'
when: cluster
- name: Get my domain names if any
set_fact:
fqdns: '{{ interfaces | map(attribute="ip_addresses") | flatten
| map(attribute="dns_name") | reject("==", "") | sort | unique }}'