-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACI_Ops_SimpleBuild.yml
179 lines (159 loc) · 5.17 KB
/
ACI_Ops_SimpleBuild.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
---
- hosts: aci
gather_facts: yes
connection: network_cli
become: yes
become_method: enable
ignore_errors: yes
tasks:
- name: account $USER
shell: "echo $USER"
register: play_user
changed_when: false
check_mode: no
- debug:
msg: "Running as '{{ play_user.stdout }}'"
- name: obtain login credentials
include_vars: "auth/secrets.yml"
- name: Set Username and Password
set_fact:
username: "{{ lab_creds['username'] }}"
password: "{{ lab_creds['password'] }}"
- name: new variable with current date time
set_fact: time_stamp="{{lookup('pipe','date \"+%m-%d-%Y_%H%M\"')}}"
- name: Set reference var
set_fact:
reference: "{{ time_stamp }}_{{ play_user.stdout }}"
- name: Load APIC Variable File
include_vars: hostvars/{{ inventory_hostname }}.yml"
- name: Pre-Build Snapshot Task
aci_config_snapshot:
host: "{{ aci_apic.ipv4 }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
state: present
export_policy: AnsibleACI_SimpleOpsBuild-{{ inventory_hostname }}-{{ reference }}
delegate_to: localhost
register: result_snapshot
when: (continue_build.user_input == "y")
- name: AP Task
aci_ap:
host: "{{ aci_apic.ipv4 }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.tenant }}"
ap: "{{ item.name }}"
description: "{{ reference }}"
state: "{{ item.state }}"
delegate_to: localhost
register: result_ap
when: (item.state == "present" or item.state == "absent" or item.state == "query")
with_items:
- "{{ aps }}"
- name: BD Task
aci_bd:
host: "{{ aci_apic.ipv4 }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.tenant}}"
vrf: "{{ item.vrf}}"
bd: "{{ item.name }}"
description: "{{ reference }}"
bd_type: "{{ item.bd_type }}"
enable_routing: "{{ item.enable_routing }}"
enable_multicast: "{{ item.enable_multicast }}"
state: "{{ item.state }}"
delegate_to: localhost
register: result_bd
when: (item.state == "present" or item.state == "absent" or item.state == "query")
with_items:
- "{{ bds }}"
- name: BD Subnet Task
aci_bd_subnet:
host: "{{ aci_apic.ipv4 }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.tenant }}"
bd: "{{ item.bd }}"
subnet_name: "{{ item.subnet_name }}"
description: "{{ reference }}"
gateway: "{{ item.gateway }}"
mask: "{{ item.mask }}"
scope: "{{ item.scope}}"
state: "{{ item.state }}"
delegate_to: localhost
register: result_bd_subnet
when: (item.state == "present" or item.state == "absent" or item.state == "query")
with_items:
- "{{ bd_subnets }}"
- name: EPG Task
aci_epg:
host: "{{ aci_apic.ipv4 }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
tenant: "{{ item.tenant }}"
bd: "{{ item.bd }}"
ap: "{{ item.ap}}"
epg: "{{ item.name }}"
description: "{{ reference }}"
state: "{{ item.state }}"
delegate_to: localhost
register: result_epg
when: (item.state == "present" or item.state == "absent" or item.state == "query")
with_items:
- "{{ epgs }}"
- name: Generate Output File
template:
src=template/simple_ops_build_output.j2
dest=output/build_output/ACI-Info-{{ time_stamp }}SimpleOpsBuild-{{ aci_apic.hostname }}.yml
when: (infoblox_update.user_input == "n")
- name: Change current present states to ignore
replace:
path: hostvars/cisco/aci/{{ inventory_hostname }}.yml"
regexp: 'state: present'
replace: 'state: ignore'
after: 'aps:'
- name: Change current absent states to ignore
replace:
path: hostvars/cisco/aci/{{ inventory_hostname }}.yml"
regexp: 'state: absent'
replace: 'state: ignore'
after: 'aps:'
- name: Change current query states to ignore
replace:
path: hostvars/cisco/aci/{{ inventory_hostname }}.yml"
regexp: 'state: query'
replace: 'state: ignore'
after: 'aps:'
- name: Email Report Recipient(s).
pause:
prompt: "Email Playbook Report? (y/n)"
echo: yes
register: mail_prompt
- name: Email Report Recipient(s).
pause:
prompt: "Target Email Address(es). Separate multiple addresses by commas"
echo: yes
register: mail_recipient
when: (mail_prompt.user_input == "y")
- name: Sending Playbook Build Output File
mail:
host: 172.16.0.1
port: 25
from: [email protected]
subject: ACI_OpsBuild_Report_{{ inventory_hostname }}
body: "See atached report"
attach: "output/build_output/ACI-Info-{{ time_stamp }}OpsBuild-{{ aci_apic.hostname }}.yml"
to: "{{ mail_recipient }}"
when: (mail_prompt.user_input == "y") and
(mail_recipient is defined)
- name: Clean Playbook Build Output File
file:
path: output/build_output/ACI-Info-{{ time_stamp }}SimpleOpsBuild-{{ aci_apic.hostname }}.yml
state: absent
...