-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
210 lines (185 loc) · 6.51 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
---
- hosts: localhost
tasks:
- name: Create the Base VM
virt_lightning.virt_lightning.vm:
distro: '{{ base.distro }}'
name: basehost
memory: 8192
state: present
- name: Refresh inventory to ensure new instaces exist in inventory
meta: refresh_inventory
- hosts: basehost
tasks:
- debug: var=ansible_distribution
- debug: var=ansible_distribution_major_version
- debug: var=ansible_distribution_version
- when: image_os == "dragonflybsd"
block:
- name: "DFly/pkg turn off SSL, see https://www.reddit.com/r/dragonflybsd/comments/q9xowg/certificate_verification_failed_for_odigital/hh0a01s/"
command: sed -i.bak 's,https:,http:,' /usr/local/etc/pkg/repos/df-latest.conf
become: true
- name: "DFly/pkg avoid pkg: invalid scheme ftp, pkg: Cannot parse configuration file!"
command: sed -i.bak 's,ftp:,http:,' /usr/local/etc/pkg/repos/df-latest.conf
become: true
- name: upgrade and install git
shell: |
pkg update
pkg install -y pkg || true
pkg update
pkg upgrade -y || true
pkg install -y git || true
pkg install -y git
become: true
- when: image_os == "freebsd"
block:
- name: upgrade and install git
shell: |
IGNORE_OSVERSION=yes pkg update
pkg install -y git
become: true
- when: ansible_distribution == 'OpenBSD' and ansible_distribution_version != image_version|string
block:
- name: Upgrade OpenBSD
command: sysupgrade -rn
become: true
- name: Unconditionally on the new version
reboot:
become: true
- name: Upgrade packages
ansible.builtin.raw: sudo pkg_add -uvi
register: result
retries: 3
until: result is not failed
- when: ansible_os_family == "NetBSD"
name: Install the dependency on NetBSD
block:
- name: install the dependencies
shell: "/usr/sbin/pkg_add -U {{ item }}"
with_items: '{{ dependencies }}'
become: true
environment:
PKG_PATH: 'http://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/{{ ansible_machine }}/{{ ansible_distribution_release }}/All'
- name: Install the rootcerts
command: /usr/pkg/sbin/mozilla-rootcerts install
become: true
args:
creates: /etc/openssl/certs/ca-certificates.crt
- debug: var=ansible_os_family
- debug: msg='pkg_add {{ dependencies| join(" ") }}'
- name: install the dependencies (OpenBSD)
command: 'pkg_add {{ dependencies| join(" ") }}'
become: true
when: ansible_os_family == "OpenBSD"
- name: install the dependencies (generic)
package:
name: '{{ dependencies }}'
become: true
when: ansible_os_family not in ["NetBSD", "OpenBSD"]
environment:
IGNORE_OSVERSION: yes
- command: git config --global http.sslVerify false
- name: Fetch the builder script
git:
repo: '{{ builder_repo }}'
dest: builder
version: master
- name: Build the images
shell: 'sudo -E bash build.sh {{ image_version }} {{ git_repo|default("canonical/cloud-init") }} {{ git_ref|default("main") }} 2>&1 | tee build.log '
args:
chdir: builder
creates: '{{ final_name }}.raw'
environment:
root_fs: '{{ root_fs|default("")}}'
PYTHON: '{{ python_interpreter }}'
register: result
- debug: var=result
- name: Download the raw image
fetch:
src: 'builder/final.raw'
dest: images/
- hosts: localhost
tasks:
- name: Export the images
command: 'qemu-img convert -f raw -O qcow2 -c images/basehost/builder/final.raw /var/lib/virt-lightning/pool/upstream/{{ final_name }}_exp.qcow2'
args:
creates: '/var/lib/virt-lightning/pool/upstream/{{ final_name }}_exp.qcow2'
- name: Write the image metadata
copy:
content: |
python_interpreter: {{ python_interpreter }}
dest: '/var/lib/virt-lightning/pool/upstream/{{ final_name }}_exp.yaml'
- name: Create the new VM
virt_lightning.virt_lightning.vm:
distro: '{{ final_name }}_exp'
name: newvm
state: present
- name: Refresh inventory to ensure new instaces exist in inventory
meta: refresh_inventory
- name: gather facts from the new host
setup:
delegate_to: newvm
delegate_facts: true
- debug: var=hostvars.newvm
- debug: var=image_version
- debug: var=image_os
- debug: var=final_name
- debug: var=hostvars.newvm.ansible_facts.os_family
- debug: var=hostvars.newvm.ansible_facts.distribution_version
- debug: var=hostvars.newvm.ansible_kernel
- assert:
that:
- "'192.168.123.1' in hostvars.newvm.ansible_dns.nameservers"
- assert:
that:
- hostvars.newvm.ansible_facts.os_family|lower == image_os
when: image_os != "dragonflybsd"
- assert:
that:
- hostvars.newvm.ansible_facts.os_family == "DragonFly"
when: image_os == "dragonflybsd"
- assert:
that:
- hostvars.newvm.ansible_facts.distribution_version == image_version|string
when: not final_name.startswith('netbsd') and not image_os == "dragonflybsd"
- assert:
that:
- hostvars.newvm.ansible_kernel == image_version|string
when: final_name.startswith('netbsd')
- command: pkgin update
become: true
delegate_to: newvm
when: final_name.startswith('netbsd')
- command: pkgin -y install curl
become: true
delegate_to: newvm
when: final_name.startswith('netbsd')
- package:
name: curl
become: true
delegate_to: newvm
when: not final_name.startswith('netbsd')
# - name: Ensure the root FS has been resized
# assert:
# that: hostvars.newvm.ansible_mounts[0].size_total > 25000000000
- command: hostname
register: newvm_hostname
delegate_to: newvm
- name: Ensure the hostname is set properly
assert:
that: newvm_hostname.stdout == "newvm"
- name: Run a command as root with su to be sure the password is set
command: uptime
vars:
become: yes
become_method: su
become_user: root
become_password: root
- name: Destroy the new VM
virt_lightning.virt_lightning.vm:
name: newvm
state: absent
- name: Destroy the VM
virt_lightning.virt_lightning.vm:
name: basehost
state: absent