@@ -13,7 +13,8 @@ opts = GetoptLong.new(
13
13
# Pass arguments to actual vagrant, but they're not used here
14
14
[ "--provider" , GetoptLong ::OPTIONAL_ARGUMENT ] ,
15
15
[ "--help" , GetoptLong ::OPTIONAL_ARGUMENT ] ,
16
- [ "--debug" , GetoptLong ::OPTIONAL_ARGUMENT ]
16
+ [ "--debug" , GetoptLong ::OPTIONAL_ARGUMENT ] ,
17
+ [ "--destroy-on-error" , GetoptLong ::OPTIONAL_ARGUMENT ]
17
18
)
18
19
19
20
local = false
@@ -47,179 +48,181 @@ end
47
48
48
49
49
50
Vagrant . configure ( "2" ) do |config |
50
- if architecture == "arm64"
51
- config . vagrant . plugins = "vagrant-libvirt"
52
- config . vm . box_architecture = architecture
53
- end
54
- config . vm . synced_folder "." , "/vagrant"
51
+ config . vm . define "ansible-playbooks_#{ Time . now . to_i } " do |node |
52
+ if architecture == "arm64"
53
+ node . vagrant . plugins = "vagrant-libvirt"
54
+ node . vm . box_architecture = architecture
55
+ end
56
+ node . vm . synced_folder "." , "/vagrant"
55
57
56
- # https://developer.hashicorp.com/vagrant/docs/vagrantfile/machine_settings
57
- config . vm . box = os
58
- config . vm . boot_timeout = 600
58
+ # https://developer.hashicorp.com/vagrant/docs/vagrantfile/machine_settings
59
+ node . vm . box = os
60
+ node . vm . boot_timeout = 600
59
61
60
- # Need to run `vagrant provision` explicitly for that to work
61
- config . trigger . after [ :provision ] do |trigger |
62
- trigger . name = "Reboot after provisioning"
63
- trigger . run = { :inline => "vagrant reload" }
64
- end
62
+ # Need to run `vagrant provision` explicitly for that to work
63
+ node . trigger . after [ :provision ] do |trigger |
64
+ trigger . name = "Reboot after provisioning"
65
+ trigger . run = { :inline => "vagrant reload" }
66
+ end
65
67
66
- # https://vagrant-libvirt.github.io/vagrant-libvirt/configuration.html
67
- # Currently libvirt is only used for arm64. However, to destroy arm machines
68
- # even if the architecture argument is not passed, we need to set all the
69
- # libvirt options anyway, in particular to make this fix work
70
- # https://github.com/vagrant-libvirt/vagrant-libvirt/pull/1329/files
71
- config . vm . provider "libvirt" do |libvirt |
72
- # Give more resources, OOMs by default
73
- libvirt . memory = 8000
74
- # Max 8 cores allowed for arm cpu
75
- libvirt . cpus = [ `nproc` . to_i , 8 ] . min
76
- libvirt . machine_type = "virt"
77
- # https://libvirt.org/formatdomain.html
78
- # In this mode, the cpu element describes the CPU that should be presented
79
- # to the guest. This is the default when no mode attribute is specified.
80
- # This mode makes it so that a persistent guest will see the same hardware
81
- # no matter what host the guest is booted on.
82
- libvirt . cpu_mode = "custom"
83
- libvirt . cpu_model = "cortex-a57"
84
- libvirt . driver = "qemu"
85
- libvirt . machine_arch = "aarch64"
86
- # Enable UEFI, refuses to work otherwise
87
- libvirt . nvram = true
88
- libvirt . loader = "/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd"
89
- # Errors otherwise
90
- libvirt . inputs = [ ]
91
- end
68
+ # https://vagrant-libvirt.github.io/vagrant-libvirt/configuration.html
69
+ # Currently libvirt is only used for arm64. However, to destroy arm machines
70
+ # even if the architecture argument is not passed, we need to set all the
71
+ # libvirt options anyway, in particular to make this fix work
72
+ # https://github.com/vagrant-libvirt/vagrant-libvirt/pull/1329/files
73
+ node . vm . provider "libvirt" do |libvirt |
74
+ # Give more resources, OOMs by default
75
+ libvirt . memory = 8000
76
+ # Max 8 cores allowed for arm cpu
77
+ libvirt . cpus = [ `nproc` . to_i , 8 ] . min
78
+ libvirt . machine_type = "virt"
79
+ # https://libvirt.org/formatdomain.html
80
+ # In this mode, the cpu element describes the CPU that should be presented
81
+ # to the guest. This is the default when no mode attribute is specified.
82
+ # This mode makes it so that a persistent guest will see the same hardware
83
+ # no matter what host the guest is booted on.
84
+ libvirt . cpu_mode = "custom"
85
+ libvirt . cpu_model = "cortex-a57"
86
+ libvirt . driver = "qemu"
87
+ libvirt . machine_arch = "aarch64"
88
+ # Enable UEFI, refuses to work otherwise
89
+ libvirt . nvram = true
90
+ libvirt . loader = "/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd"
91
+ # Errors otherwise
92
+ libvirt . inputs = [ ]
93
+ end
92
94
93
- config . vm . provider "virtualbox" do |vb |
94
- # Give more resources, OOMs by default
95
- vb . memory = 8000
96
- vb . cpus = `nproc` . to_i
95
+ node . vm . provider "virtualbox" do |vb |
96
+ # Give more resources, OOMs by default
97
+ vb . memory = 8000
98
+ vb . cpus = `nproc` . to_i
97
99
98
- # Make UI fast
99
- vb . gui = gui
100
- if gui
101
- vb . customize [ "modifyvm" , :id , "--vram" , "128" ]
102
- vb . customize [ "modifyvm" , :id , "--accelerate3d" , "on" ]
103
- end
100
+ # Make UI fast
101
+ vb . gui = gui
102
+ if gui
103
+ vb . customize [ "modifyvm" , :id , "--vram" , "128" ]
104
+ vb . customize [ "modifyvm" , :id , "--accelerate3d" , "on" ]
105
+ end
104
106
105
- # Disable annoying warnings
106
- vb . check_guest_additions = false
107
- end
107
+ # Disable annoying warnings
108
+ vb . check_guest_additions = false
109
+ end
108
110
109
- if local
110
- config . vm . provision "shell" , env : { } , inline : <<-SHELL
111
- set -uex
111
+ if local
112
+ node . vm . provision "shell" , env : { } , inline : <<-SHELL
113
+ set -uex
112
114
113
- export DEBIAN_FRONTEND=noninteractive
115
+ export DEBIAN_FRONTEND=noninteractive
114
116
115
- systemctl disable systemd-networkd.service
117
+ systemctl disable systemd-networkd.service
116
118
117
- rm -f /etc/resolv.conf
118
- echo "nameserver 8.8.8.8" > /etc/resolv.conf
119
+ rm -f /etc/resolv.conf
120
+ echo "nameserver 8.8.8.8" > /etc/resolv.conf
119
121
120
- TMPDIR=$(mktemp -d)
121
- cd "${TMPDIR}"
122
+ TMPDIR=$(mktemp -d)
123
+ cd "${TMPDIR}"
122
124
123
- rm -rf ansible-playbooks
124
- cp -R /vagrant ansible-playbooks
125
+ rm -rf ansible-playbooks
126
+ cp -R /vagrant ansible-playbooks
125
127
126
- cd ansible-playbooks
127
- rm -rf manual
128
- mkdir manual
128
+ cd ansible-playbooks
129
+ rm -rf manual
130
+ mkdir manual
129
131
130
- sed 's/# //g' roles/user/defaults/main.yml > manual/common.yml
132
+ sed 's/# //g' roles/user/defaults/main.yml > manual/common.yml
131
133
132
- chown -R vagrant .
134
+ chown -R vagrant .
133
135
134
- set +e
135
- for i in {1..3}; do
136
- # Run twice to make sure users are added to correct groups
137
- sudo -u vagrant ./bootstrap.sh #{ playbook } LOCAL && \
136
+ set +e
137
+ for i in {1..3}; do
138
+ # Run twice to make sure users are added to correct groups
138
139
sudo -u vagrant ./bootstrap.sh #{ playbook } LOCAL && \
139
- break
140
- done
140
+ sudo -u vagrant ./bootstrap.sh #{ playbook } LOCAL && \
141
+ break
142
+ done
141
143
142
- if [[ $? -ne 0 ]]; then
143
- echo "Failed to provision"
144
- exit 1
145
- fi
146
- set -e
144
+ if [[ $? -ne 0 ]]; then
145
+ echo "Failed to provision"
146
+ exit 1
147
+ fi
148
+ set -e
147
149
148
- apt-get update
149
- apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
150
+ apt-get update
151
+ apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
150
152
151
- apt-get update
152
- apt-get dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
153
+ apt-get update
154
+ apt-get dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
153
155
154
- apt-get update
155
- apt-get upgrade -y
156
+ apt-get update
157
+ apt-get upgrade -y
156
158
157
- apt-get autoremove -y
158
- apt purge -y '~c'
159
+ apt-get autoremove -y
160
+ apt purge -y '~c'
159
161
160
- id -u user && cd /tmp/ && sudo -u user /home/user/.bin/init-user-env.sh || true
162
+ id -u user && cd /tmp/ && sudo -u user /home/user/.bin/init-user-env.sh || true
161
163
162
- reboot
163
- SHELL
164
- else
165
- config . vm . provision "shell" , env : { } , inline : <<-SHELL
166
- set -uex
164
+ reboot
165
+ SHELL
166
+ else
167
+ node . vm . provision "shell" , env : { } , inline : <<-SHELL
168
+ set -uex
167
169
168
- export DEBIAN_FRONTEND=noninteractive
170
+ export DEBIAN_FRONTEND=noninteractive
169
171
170
- systemctl disable systemd-networkd.service
172
+ systemctl disable systemd-networkd.service
171
173
172
- rm -f /etc/resolv.conf
173
- echo "nameserver 8.8.8.8" > /etc/resolv.conf
174
+ rm -f /etc/resolv.conf
175
+ echo "nameserver 8.8.8.8" > /etc/resolv.conf
174
176
175
- TMPDIR=$(mktemp -d)
176
- cd "${TMPDIR}"
177
+ TMPDIR=$(mktemp -d)
178
+ cd "${TMPDIR}"
177
179
178
- export DEBIAN_FRONTEND=noninteractive
180
+ export DEBIAN_FRONTEND=noninteractive
179
181
180
- apt-get update
182
+ apt-get update
181
183
182
- apt-get install -y git
184
+ apt-get install -y git
183
185
184
- rm -rf ansible-playbooks
185
- git clone https://github.com/fspv/ansible-playbooks.git
186
+ rm -rf ansible-playbooks
187
+ git clone https://github.com/fspv/ansible-playbooks.git
186
188
187
- cd ansible-playbooks
188
- mkdir manual
189
+ cd ansible-playbooks
190
+ mkdir manual
189
191
190
- sed 's/# //g' roles/user/defaults/main.yml > manual/common.yml
192
+ sed 's/# //g' roles/user/defaults/main.yml > manual/common.yml
191
193
192
- chown -R vagrant .
194
+ chown -R vagrant .
193
195
194
- set +e
195
- if [[ $? -ne 0 ]]; then
196
- # Run twice to make sure users are added to correct groups
197
- sudo -u vagrant ./bootstrap.sh #{ playbook } LOCAL && \
196
+ set +e
197
+ if [[ $? -ne 0 ]]; then
198
+ # Run twice to make sure users are added to correct groups
198
199
sudo -u vagrant ./bootstrap.sh #{ playbook } LOCAL && \
199
- break
200
- done
200
+ sudo -u vagrant ./bootstrap.sh #{ playbook } LOCAL && \
201
+ break
202
+ done
201
203
202
- if $? -ne 0; then
203
- echo "Failed to provision"
204
- exit 1
205
- fi
206
- set -e
204
+ if $? -ne 0; then
205
+ echo "Failed to provision"
206
+ exit 1
207
+ fi
208
+ set -e
207
209
208
- apt-get update
209
- apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
210
+ apt-get update
211
+ apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
210
212
211
- apt-get update
212
- apt-get dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
213
+ apt-get update
214
+ apt-get dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
213
215
214
- apt-get update
215
- apt-get upgrade -y
216
+ apt-get update
217
+ apt-get upgrade -y
216
218
217
- apt-get autoremove -y
218
- apt purge -y '~c'
219
+ apt-get autoremove -y
220
+ apt purge -y '~c'
219
221
220
- id -u user && cd /tmp/ && sudo -u user /home/user/.bin/init-user-env.sh || true
222
+ id -u user && cd /tmp/ && sudo -u user /home/user/.bin/init-user-env.sh || true
221
223
222
- reboot
223
- SHELL
224
+ reboot
225
+ SHELL
226
+ end
224
227
end
225
228
end
0 commit comments