-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
229 lines (209 loc) · 6.29 KB
/
playbook.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
---
- name: Generate vars.yml from XLSX
hosts: localhost
connection: local
gather_facts: no
vars:
defcon_query: "[?Parameter=='DefaultContract'].Value|[0]"
xls_file: "aci.xlsx"
tasks:
- name: Get facts from XLSX file
xls_to_facts:
src: "{{ xls_file }}"
# - debug:
# msg: "{{ ansible_facts }}"
- name: Extract DefaultContract setting
set_fact:
DefaultContract: "{{ spreadsheet_Settings | json_query(defcon_query) }}"
- name: Extract application
set_fact:
apps: "{{ spreadsheet_Sheet2 | json_query('[*].Application') }}"
- name: Ensure vars directory exists
file:
path: vars
state: directory
- name: Create vars.yml
template:
src: templates/vars.j2
dest: vars/vars.yml
- name: Apply settings to APIC
hosts: apic
connection: local
vars_files:
- vars/vars.yml
gather_facts: no
tasks:
- name: Create tenants
aci_tenant:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.name }}"
description: "{{ item.description }}"
state: present
loop: "{{ tenants | flatten(levels=1) }}"
- name: Add a new filter to a tenant
aci_filter:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
filter: "{{ item.1.name }}"
description: "{{ item.1.description }}"
tenant: "{{ item.0.name }}"
state: present
with_subelements:
- "{{ tenants }}"
- filters
- name: Add filter entry
aci_filter_entry:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
entry: "{{ item.1.entry.name }}"
ether_type: "{{ item.1.entry.ether_type }}"
filter: "{{ item.1.filter }}"
tenant: "{{ item.0.tenant }}"
state: present
with_subelements:
- "{{ tenants | json_query('[*].{tenant:name, entries:filters[].{entry:entries[] | [0], filter:name}}') }}"
- entries
- name: Create VRFs
aci_vrf:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
vrf: "{{ item.1.name }}"
tenant: "{{ item.0.name }}"
descr: "{{ item.1.description }}"
state: present
with_subelements:
- "{{ tenants }}"
- vrfs
- name: Create Bridge Domains
aci_bd:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.tenant }}"
bd: "{{ item.1.bd.name }}"
vrf: "{{ item.1.vrf }}"
state: present
with_subelements:
- "{{ tenants | json_query('[*].{tenant:name, bds:vrfs[].{bd:bds[] | [0], vrf:name}}') }}"
- bds
- name: Create a subnets
aci_bd_subnet:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.tenant }}"
bd: "{{ item.1.bd.name }}"
gateway: "{{ item.1.bd.gw }}"
mask: "{{ item.1.bd.mask }}"
state: present
with_subelements:
- "{{ tenants | json_query('[*].{tenant:name, bds:vrfs[].{bd:bds[] | [0], vrf:name}}') }}"
- bds
- name: Create applications
aci_ap:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.name }}"
ap: "{{ item.1 }}"
state: present
with_subelements:
- "{{ tenants }}"
- apps
- name: Create EPGs
aci_epg:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.name }}"
ap: "{{ item.1.ap }}"
epg: "{{ item.1.name }}"
bd: "{{ item.1.bd }}"
state: present
with_subelements:
- "{{ tenants }}"
- epgs
- name: Create contracts
aci_contract:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.name }}"
contract: "{{ item.1.name }}"
scope: application-profile
state: present
with_subelements:
- "{{ tenants }}"
- contracts
- name: Create contract subjects
aci_contract_subject:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.name }}"
contract: "{{ item.1.name }}"
subject: "{{ item.1.subj }}"
reverse_filter: yes
state: present
with_subelements:
- "{{ tenants }}"
- contracts
- name: Bind contract subject to filter
aci_contract_subject_to_filter:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.name }}"
contract: "{{ item.1.name }}"
subject: "{{ item.1.subj }}"
filter: "{{ item.1.filter }}"
state: present
with_subelements:
- "{{ tenants }}"
- contracts
- name: Bind contract to EPG (provider)
aci_epg_to_contract:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.name }}"
ap: "{{ item.1.ap }}"
epg: "{{ item.1.name }}"
contract: "{{ item.1.contract }}"
contract_type: provider
state: present
with_subelements:
- "{{ tenants }}"
- epgs
- name: Bind contract to EPG (consumer)
aci_epg_to_contract:
host: "{{ ansible_host }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.0.name }}"
ap: "{{ item.1.ap }}"
epg: "{{ item.1.name }}"
contract: "{{ item.1.contract }}"
contract_type: consumer
state: present
with_subelements:
- "{{ tenants }}"
- epgs