-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtenant-vrf-matrix.yml
69 lines (51 loc) · 2.02 KB
/
tenant-vrf-matrix.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
- name: Configure base stuff like tenant,vrf, l3out, extepg, etc.
hosts: dedicated
gather_facts: false
connection: local
vars:
aci_login: &aci_login
hostname: '{{ ansible_host }}'
username: '{{ local_apic_user }}'
certificate_name: '{{ cert_name }}'
private_key: "{{ lookup('file', 'group_vars/{{ group_names[0] }}/ComeBack-Cert.key') }}"
validate_certs: false
tasks:
- name: Grabbing All tenants details
aci_rest:
<<: *aci_login
path: /api/node/class/fvTenant.json?query-target-filter=and(not(wcard(fvTenant.dn,"uni/tn-common")),not(wcard(fvTenant.dn,"uni/tn-infra")),not(wcard(fvTenant.dn,"uni/tn-mgmt")))
method: get
register: all_tenants
- name: Set the found Tenatns in a List
set_fact:
found_dns: "{{ found_dns | default([]) + [all_tenants.imdata | json_query(jquery) | flatten ] | flatten }}"
vars:
jquery: "[*].fvTenant.attributes.dn"
- name: Filter The list further
set_fact:
found_tns: "{{ found_dns | regex_replace('uni/tn-','') }}"
vars:
jquery: "[*].fvTenant.attributes.dn"
- name: print list of found Tenants
debug:
msg: "{{ found_tns }}"
- name: Grabbing all VRFs for all Tenants.
aci_rest:
<<: *aci_login
path: /api/node/class/fvCtx.json?query-target-filter=wcard(fvCtx.dn,"uni/tn-{{ item }}")
method: get
with_items: "{{ found_tns }}"
register: allvrfs
- name: Extract count of VRFs per Tenant
set_fact:
found_vrfs_length: "{{ found_vrfs_length | default([]) + [allvrfs.results | to_json | from_json | json_query(jquery) | flatten | length] }}"
vars:
- jquery: "[].imdata[?starts_with(fvCtx.attributes.dn, 'uni/tn-{{ item }}/')]"
with_items: "{{ found_tns }}"
- name: Combine two lists (tenants and their VRFs count) into a dictionary
set_fact:
tenants_and_vrf_lengths: "{{ dict(found_tns |zip(found_vrfs_length)) }}"
- name: Print the List of Tenant and VRFs Length
debug:
msg: "{{ tenants_and_vrf_lengths }}"