forked from marvel-nccr/quantum-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook-package.yml
178 lines (145 loc) · 4.79 KB
/
playbook-package.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
- name: Package VM
hosts: 127.0.0.1
connection: local
vars:
tmp_vdisk_vdi: "tmp.vdi"
tmp_vdisk_vmdk: "tmp.vmdk"
tasks:
- name: set VM ID
set_fact:
vm_id: "{{ vm_name }} {{ vm_version }}"
tags: [always]
- name: Get machine information for "{{ vm_id }}"
shell: vboxmanage showvminfo --machinereadable "{{ vm_id }}"
register: vminfo
tags: [always]
- name: set VM machine information
set_fact:
vdisk_path: "{{ vminfo.stdout | regex_search('\"SATA Controller-0-0\"=\"(.+)\"', '\\1') | first }}"
vdisk_uuid: "{{ vminfo.stdout | regex_search('\"SATA Controller-ImageUUID-0-0\"=\"(.+)\"', '\\1') | first }}"
tags: [always]
- name: Get stats of {{ vdisk_path }}
stat:
path: "{{ vdisk_path }}"
register: vm_vdisk_file
tags: [always]
- debug:
msg: "vdisk size: {{ vm_vdisk_file.stat.size | filesizeformat }}"
tags: [always]
- name: Reload VM (to ensure /tmp wiped)
shell: vagrant reload
tags: [clean, reload]
- name: Output SSH connection configuration
shell: vagrant ssh-config > vagrant-ssh
tags: [clean]
- name: Clear bash history
shell: ssh -F vagrant-ssh default "cat /dev/null > ~/.bash_history && history -c"
tags: [clean]
- name: Filling free space with zeros (this can take several minutes)
shell: ssh -F vagrant-ssh default "cat /dev/zero > zero.fill; sync; sleep 1; sync; rm -f zero.fill"
tags: [clean]
- name: Halt any running machines
shell: vagrant halt
tags: [always]
- name: Disable the virtual network created by vagrant
shell: vboxmanage modifyvm "{{ vm_id }}" --nic2 none
tags: [always]
- name: Remove old temporary files
file:
path: "{{ item }}"
state: absent
with_items:
- "{{ tmp_vdisk_vdi }}"
- "{{ tmp_vdisk_vmdk }}"
tags: [compact]
- name: Convert vdisk to vdi format
shell: vboxmanage clonehd "{{ vdisk_path }}" "{{ tmp_vdisk_vdi }}" --format vdi
tags: [compact]
- name: Compact vdisk
shell: vboxmanage modifyhd "{{ tmp_vdisk_vdi }}" --compact
tags: [compact]
- name: Convert vdisk back to vmdk
shell: vboxmanage clonehd "{{ tmp_vdisk_vdi }}" "{{ tmp_vdisk_vmdk }}" --format vmdk
tags: [compact]
- name: Remove vdi temporary file
shell: vboxmanage closemedium "{{ tmp_vdisk_vdi }}" --delete
tags: [compact]
- name: Replace VM file
copy:
src: "{{ tmp_vdisk_vmdk }}"
dest: "{{ vdisk_path }}"
force: true
tags: [compact]
- name: Reset VM UUID
shell: vboxmanage internalcommands sethduuid "{{ vdisk_path }}" {{ vdisk_uuid }}
tags: [compact]
- name: Remove vdmk temporary file
shell: vboxmanage closemedium "{{ tmp_vdisk_vmdk }}" --delete
tags: [compact]
- name: Get stats of {{ vdisk_path }}
stat:
path: "{{ vdisk_path }}"
register: vm_vdisk_file
tags: [clean, compact]
- debug:
msg: "Final vdisk size: {{ vm_vdisk_file.stat.size | filesizeformat }}"
tags: [clean, compact]
# - name: Retrieve git tag
# shell: git describe --abbrev=0 --tags
# register: git_tag
# tags: [export, validate, skip_ansible_lint]
# - name: "Assert git tag ({{ git_tag.stdout }}) == VM version({{ vm_version }})"
# assert:
# that:
# - git_tag.stdout == vm_version
# tags: [export, validate]
- name: Make dist folder
file:
state: directory
path: "{{ local_dist_folder }}/"
tags: [export]
- name: set output path for image
set_fact:
image_path: "{{ local_dist_folder }}/siesta_mobile_{{ vm_version }}.ova"
tags: [export, release]
- name: Remove old image file
file:
state: absent
path: "{{ image_path }}"
tags: [export]
- name: "Export image to: {{ image_path }}"
shell: |
vboxmanage export "{{ vm_id }}" \
-o {{ image_path }} \
--vsys 0 \
--product "{{ vm_name }}" \
--version "{{ vm_version }}" \
--producturl "{{ vm_url }}" \
--vendor "{{ vm_author }}" \
--vendorurl "{{ vm_author_url }}" \
--description "{{ vm_description }}" \
--eulafile "resources/EULA.txt"
tags: [export]
- name: Get stats of {{ image_path }}
stat:
path: "{{ image_path }}"
get_checksum: true
checksum_algorithm: md5
register: vm_image_file
tags: [export, release]
- debug:
msg: "image size: {{ vm_image_file.stat.size | filesizeformat }}"
tags: [export, release]
- name: Get Virtual Box version
command: vboxmanage --version
register: vbox_version
tags: [export, release]
- name: Get Vagrant version
command: vagrant --version
register: vagrant_version
tags: [export, release]
- name: Add release template to dist folder
template:
src: resources/Release.md.j2
dest: "{{ release_instructions }}"
tags: [export, release]