-
Notifications
You must be signed in to change notification settings - Fork 1
/
customize_ovas.yml
207 lines (187 loc) · 10.2 KB
/
customize_ovas.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
---
# From yfauser one-cloud-nsxt
- name: Customize OVA Files
hosts: localhost
gather_facts: True
vars_files:
- ./customize_ova_vars.yml
tasks:
# - name: retrieve the OVA URLs and Filenames from the Buildweb API
# buildweb_uris: build_id={{ nsx_build_number }}
# tags: set_facts
- name: Set target OVF Filename for Manager
set_fact: nsx_manager_ovf="{{ nsx_manager_filename | regex_replace('ova', 'ovf') }}"
tags: set_facts
- name: Set target OVF Filename for Controller
set_fact: nsx_controller_ovf="{{ nsx_controller_filename | regex_replace('ova', 'ovf') }}"
tags: set_facts
- name: Set target OVF Filename for Gw
set_fact: nsx_gw_ovf="{{ nsx_gw_filename | regex_replace('ova', 'ovf') }}"
tags: set_facts
- name: Set target OVF Path for Manager
set_fact: nsx_manager_path="{{ nsx_manager_filename | regex_replace('.ova', '') }}"
tags: set_facts
- name: Set target OVF Path for Controller
set_fact: nsx_controller_path="{{ nsx_controller_filename | regex_replace('.ova', '') }}"
tags: set_facts
- name: Set target OVF Path for Gw
set_fact: nsx_gw_path="{{ nsx_gw_filename | regex_replace('.ova', '') }}"
tags: set_facts
- name: Set target MF Filename for Manager
set_fact: nsx_manager_mf="{{ nsx_manager_filename | regex_replace('ova$', 'mf') | regex_replace('ova', 'ovf') }}"
tags: set_facts
- name: Set target MF Filename for Controller
set_fact: nsx_controller_mf="{{ nsx_controller_filename | regex_replace('ova$', 'mf') | regex_replace('ova', 'ovf') }}"
tags: set_facts
- name: Set target MF Filename for Gw
set_fact: nsx_gw_mf="{{ nsx_gw_filename | regex_replace('ova$', 'mf') | regex_replace('ova', 'ovf') }}"
tags: set_facts
- name: create the target OVF folders
file: path="{{ ova_file_path }}/{{ item }}" state=directory
with_items:
- "{{ nsx_manager_path }}"
- "{{ nsx_controller_path }}"
- "{{ nsx_gw_path }}"
tags: create_pathes
- name: extract OVFs from OVAs using ovftool
command: "{{ ovftool_path }}/ovftool --allowExtraConfig {{ ova_file_path }}/{{ item.ova_filename }} {{ ova_file_path }}/{{ item.path }}/{{ item.ovf_filename }}"
args:
creates: "{{ ova_file_path }}/{{ item.path }}/{{ item.ovf_filename }}"
with_items:
- { path: "{{ nsx_manager_path }}", ovf_filename: "{{ nsx_manager_ovf }}", ova_filename: "{{ nsx_manager_filename }}" }
- { path: "{{ nsx_controller_path }}", ovf_filename: "{{ nsx_controller_ovf }}", ova_filename: "{{ nsx_controller_filename }}" }
- { path: "{{ nsx_gw_path }}", ovf_filename: "{{ nsx_gw_ovf }}", ova_filename: "{{ nsx_gw_filename }}" }
tags: extract
register: ova_extract
async: 4000
poll: 0
- name: Wait 2 minutes before checking for extraction status
pause: minutes=2
- name: ova extraction result check
async_status: jid={{ item.ansible_job_id }}
register: job_result
until: job_result.finished
with_items: "{{ ova_extract.results }}"
retries: 200
- name: remove reservations from OVF Files
lineinfile:
dest: "{{ ova_file_path }}/{{ item.path }}/{{ item.ovf_filename }}"
regexp: "Reservation"
state: absent
with_items:
- { path: "{{ nsx_manager_path }}", ovf_filename: "{{ nsx_manager_ovf }}" }
- { path: "{{ nsx_controller_path }}", ovf_filename: "{{ nsx_controller_ovf }}" }
- { path: "{{ nsx_gw_path }}", ovf_filename: "{{ nsx_gw_ovf }}" }
when: nsx_t_keep_reservation is defined and nsx_t_keep_reservation == false
tags: reservations
# - name: size down NSX Manager
# replace:
# dest: "{{ ova_file_path }}/{{ nsx_manager_path }}/{{ nsx_manager_ovf }}"
# regexp: "{{ item.regexp }}"
# replace: "{{ item.replace}}"
# with_items:
# - { regexp: "4 virtual CPU", replace: "{{nsx_t_sizing.mgr.cpu}} virtual CPU" }
# - { regexp: "<rasd:VirtualQuantity>4</rasd:VirtualQuantity>", replace: "<rasd:VirtualQuantity>{{nsx_t_sizing.mgr.cpu}}</rasd:VirtualQuantity>" }
# - { regexp: "16384 MB of memory", replace: "{{nsx_t_sizing.mgr.memory}} MB of memory" }
# - { regexp: "<rasd:VirtualQuantity>16384</rasd:VirtualQuantity>", replace: "<rasd:VirtualQuantity>{{nsx_t_sizing.mgr.memory}}</rasd:VirtualQuantity>" }
# - { regexp: "32768MB of memory", replace: "{{nsx_t_sizing.mgr.memory}} MB of memory" }
# - { regexp: "<rasd:VirtualQuantity>32768</rasd:VirtualQuantity>", replace: "<rasd:VirtualQuantity>{{nsx_t_sizing.mgr.memory}}</rasd:VirtualQuantity>" }
# tags: downsize_nsxman
# - name: size down NSX Controller
# replace:
# dest: "{{ ova_file_path }}/{{ nsx_controller_path }}/{{ nsx_controller_ovf }}"
# regexp: "{{ item.regexp }}"
# replace: "{{ item.replace}}"
# with_items:
# - { regexp: "4 virtual CPU", replace: "{{nsx_t_sizing.controller.cpu}} virtual CPU" }
# - { regexp: "<rasd:VirtualQuantity>4</rasd:VirtualQuantity>", replace: "<rasd:VirtualQuantity>{{nsx_t_sizing.controller.cpu}}</rasd:VirtualQuantity>" }
# - { regexp: "16384 MB of memory", replace: "{{nsx_t_sizing.controller.memory}} MB of memory" }
# - { regexp: "<rasd:VirtualQuantity>16384</rasd:VirtualQuantity>", replace: "<rasd:VirtualQuantity>{{nsx_t_sizing.controller.memory}}</rasd:VirtualQuantity>" }
# tags: downsize_nsxcont
# - name: change size of NSX Edge
# replace:
# dest: "{{ ova_file_path }}/{{ nsx_gw_path }}/{{ nsx_gw_ovf }}"
# regexp: "{{ item.regexp }}"
# replace: "{{ item.replace}}"
# with_items:
# - { regexp: "4 virtual CPU", replace: "{{nsx_t_sizing.edge.cpu}} virtual CPU" }
# - { regexp: "<rasd:VirtualQuantity>4</rasd:VirtualQuantity>", replace: "<rasd:VirtualQuantity>{{nsx_t_sizing.edge.cpu}}</rasd:VirtualQuantity>" }
# - { regexp: "16384 MB of memory", replace: "{{nsx_t_sizing.edge.memory}} MB of memory" }
# - { regexp: "<rasd:VirtualQuantity>16384</rasd:VirtualQuantity>", replace: "<rasd:VirtualQuantity>{{nsx_t_sizing.edge.memory}}</rasd:VirtualQuantity>" }
# - { regexp: "32768MB of memory", replace: "{{nsx_t_sizing.edge.memory}} MB of memory" }
# - { regexp: "<rasd:VirtualQuantity>32768</rasd:VirtualQuantity>", replace: "<rasd:VirtualQuantity>{{nsx_t_sizing.edge.memory}}</rasd:VirtualQuantity>" }
# tags: downsize_nsxcont
- name: calculate new NSX Manager OVF File Checksum
stat:
checksum_algorithm: sha256
path: "{{ ova_file_path }}/{{ nsx_manager_path }}/{{ nsx_manager_ovf }}"
register: nsx_man_checksum
tags: calc_checksum
- name: calculate new NSX Controller OVF File Checksum
stat:
checksum_algorithm: sha256
path: "{{ ova_file_path }}/{{ nsx_controller_path }}/{{ nsx_controller_ovf }}"
register: nsx_cont_checksum
tags: calc_checksum
- name: calculate new NSX Gw OVF File Checksum
stat:
checksum_algorithm: sha256
path: "{{ ova_file_path }}/{{ nsx_gw_path }}/{{ nsx_gw_ovf }}"
register: nsx_gw_checksum
tags: calc_checksum
- name: delete old checksum in .mf file
lineinfile:
dest: "{{ ova_file_path }}/{{ item.path }}/{{ item.mf_filename }}"
regexp: "{{ item.ovf_filename }}"
state: absent
with_items:
- { path: "{{ nsx_manager_path }}", mf_filename: "{{ nsx_manager_mf }}", ovf_filename: "{{ nsx_manager_ovf }}"}
- { path: "{{ nsx_controller_path }}", mf_filename: "{{ nsx_controller_mf }}", ovf_filename: "{{ nsx_controller_ovf }}"}
- { path: "{{ nsx_gw_path }}", mf_filename: "{{ nsx_gw_mf }}", ovf_filename: "{{ nsx_gw_ovf }}"}
tags: fix_mf_file
- name: add new checksum in .mf file
lineinfile:
dest: "{{ ova_file_path }}/{{ item.path }}/{{ item.mf_filename }}"
line: "SHA256({{ item.ovf_filename }})= {{ item.checksum }}"
state: present
with_items:
- { path: "{{ nsx_manager_path }}", mf_filename: "{{ nsx_manager_mf }}", ovf_filename: "{{ nsx_manager_ovf }}", checksum: "{{ nsx_man_checksum.stat.checksum }}" }
- { path: "{{ nsx_controller_path }}", mf_filename: "{{ nsx_controller_mf }}", ovf_filename: "{{ nsx_controller_ovf }}", checksum: "{{ nsx_cont_checksum.stat.checksum }}" }
- { path: "{{ nsx_gw_path }}", mf_filename: "{{ nsx_gw_mf }}", ovf_filename: "{{ nsx_gw_ovf }}", checksum: "{{ nsx_gw_checksum.stat.checksum }}" }
tags: fix_mf_file
- name: delete old ova files
file:
path: "{{ ova_file_path }}/{{ item.ova_filename }}"
state: absent
with_items:
- { path: "{{ nsx_manager_path }}", ova_filename: "{{ nsx_manager_filename }}" }
- { path: "{{ nsx_controller_path }}", ova_filename: "{{ nsx_controller_filename }}" }
- { path: "{{ nsx_gw_path }}", ova_filename: "{{ nsx_gw_filename }}" }
tags: delete_ovas
- name: zip OVFs to OVAs using ovftool
command: "{{ ovftool_path }}/ovftool --allowExtraConfig {{ ova_file_path }}/{{ item.path }}/{{ item.ovf_filename }} {{ ova_file_path }}/{{ item.ova_filename }}"
args:
creates: "item.path"
with_items:
- { path: "{{ nsx_manager_path }}", ovf_filename: "{{ nsx_manager_ovf }}", ova_filename: "{{ nsx_manager_filename }}" }
- { path: "{{ nsx_controller_path }}", ovf_filename: "{{ nsx_controller_ovf }}", ova_filename: "{{ nsx_controller_filename }}" }
- { path: "{{ nsx_gw_path }}", ovf_filename: "{{ nsx_gw_ovf }}", ova_filename: "{{ nsx_gw_filename }}" }
tags: compact
register: ova_compact
async: 4000
poll: 0
- name: Wait 2 minutes before checking for compaction status
pause: minutes=2
- name: compaction result check
async_status: jid={{ item.ansible_job_id }}
register: job_result
until: job_result.finished
with_items: "{{ ova_compact.results }}"
retries: 200
- name: remove OVF Folders with all Files
file: path="{{ ova_file_path }}/{{ item }}" state=absent
with_items:
- "{{ nsx_manager_path }}"
- "{{ nsx_controller_path }}"
- "{{ nsx_gw_path }}"
tags: delete_paths