Rework service handling
Allow running playbooks without NetBox access. Mainly to bootstrap NetBox itself. Would prefer not to access network from filter plugins, so maybe do that at some point also.
This commit is contained in:
parent
38c3464279
commit
29598ef4bb
5 changed files with 34 additions and 27 deletions
|
@ -1,18 +1,21 @@
|
|||
# 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") }}'
|
||||
- when: lookup("env", "NETBOX_API") != ""
|
||||
block:
|
||||
- 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
|
||||
- when: 'cluster is defined'
|
||||
block:
|
||||
- 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") }}'
|
||||
|
||||
- name: Get my domain names if any
|
||||
set_fact:
|
||||
fqdns: '{{ interfaces | map(attribute="ip_addresses") | flatten
|
||||
| map(attribute="dns_name") | reject("==", "") | sort | unique }}'
|
||||
- name: Get cluster services
|
||||
set_fact:
|
||||
cluster_services: '{{ (cluster_services|default([])) + query("netbox.netbox.nb_lookup", "services", raw_data=true, api_filter="id="+item) }}'
|
||||
loop: '{{ cluster.custom_fields.services | map(attribute="id") | map("string") }}'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue