-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
vagrant.yml
486 lines (423 loc) · 17 KB
/
vagrant.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
---
########################################
# AdoptOpenJDK - Ansible Playbook for: #
# ------------- Vagrant --------------#
########################################
- name: Vagrant playbook
hosts: all
gather_facts: yes
remote_user: root
become: yes
vars:
# Jenkins User Variables:
Jenkins_Username: jenkins
# Jenkins_User_SSHKey: "Update This With Jenkins User SSH Key"
tasks:
- name: Vagrant playbook
block:
- name: Print facts
debug:
msg:
- "inventory_hostname: {{ inventory_hostname | default('***Undefined***') }} "
- "ansible_hostname: {{ ansible_hostname | default('***Undefined***') }}"
- "ansible_fqdn: {{ ansible_fqdn | default('***Undefined***') }}"
- "ansible_user: {{ ansible_user | default('***Undefined***') }}"
- "ansible_default_ipv4.address: {{ ansible_default_ipv4.address | default('***Undefined***') }}"
- "ansible_os_family: {{ ansible_os_family | default('***Undefined***') }} "
- "ansible_distribution: {{ ansible_distribution | default('***Undefined***') }} "
- "ansible_distribution_major_version: {{ ansible_distribution_major_version | default('***Undefined***') }} "
- "ansible_architecture: {{ ansible_architecture | default('***Undefined***') }} "
- "ansible_processor_vcpus: {{ ansible_processor_vcpus | default('***Undefined***') }} "
- "ansible_processor_cores: {{ ansible_processor_cores | default('***Undefined***') }} "
- name: Install pre-reqs
apt:
name: "{{ packages }}"
update_cache: yes
vars:
packages:
- software-properties-common
- tree
- zlib1g
- zlib1g-dev
- python3-pip
- python-is-python3
- build-essential
- gettext
- libcurl4-openssl-dev
- sshpass
# Pre-Reqs For Vbox
- libssl-dev
- libvpx-dev
- libsdl-ttf2.0-0
- evince
- name: Run apt-get upgrade
apt: upgrade=safe update_cache=yes
tags: patch_update
- name: Pip install winrm modules
pip:
executable: /usr/bin/pip
name: ["requests-credssp", "pywinrm"]
- name: Create tmp folder if necessary
file:
path: /tmp
state: directory
- name: Create /usr/lib/jvm if necessary
file:
path: /usr/lib/jvm
state: directory
##########
# Java 8 #
##########
- name: Check if jdk8 is already installed in the target location
shell: ls -ld /usr/lib/jvm/jdk8* >/dev/null 2>&1
failed_when: false
register: adoptopenjdk_installed
tags: java
- name: Check if there is a default java
shell: java -version >/dev/null 2>&1
failed_when: false
register: default_java
tags: java
- name: Install latest jdk8 release if not already installed
unarchive:
src: https://api.adoptopenjdk.net/v3/binary/latest/8/ga/linux/x64/jdk/hotspot/normal/adoptopenjdk?project=jdk
dest: /usr/lib/jvm
remote_src: yes
when:
- adoptopenjdk_installed.rc != 0
tags: java
# This is due to ansible not liking wildcard searches in the file module :(
- name: Find jdk8 folder in /usr/lib/jvm
find:
paths: /usr/lib/jvm
file_type: directory
contains: jdk8u*
register: jdk8_folder
when: default_java.rc != 0
tags: java
# There should only be one jdk8u* folder in /usr/lib/jvm, hence 'files[0]'
- name: Make jdk8 the default java
file:
src: "{{ jdk8_folder.files[0].path }}{{ item }}"
dest: /usr{{ item }}
state: link
with_items:
- /bin/java
- /bin/javac
when: default_java.rc != 0
tags: java
###########
# Java 21 #
###########
- name: Check if jdk-21 is already installed in the target location
shell: ls -ld /usr/lib/jvm/jdk-21 >/dev/null 2>&1
failed_when: false
register: jdk21_installed
changed_when: false
tags: java
- name: Download the Latest JDK21 OpenJDK tar.gz file via the API
get_url:
url: "https://api.adoptium.net/v3/binary/latest/21/ga/linux/x64/jdk/hotspot/normal/eclipse?project=jdk"
dest: "/tmp/JDK21.tar.gz"
when: jdk21_installed.rc != 0
tags: java
- name: Install JDK21 if one not already installed
unarchive:
src: /tmp/JDK21.tar.gz
dest: /usr/lib/jvm
remote_src: yes
when: jdk21_installed.rc != 0
tags: java
- name: Remove Download JDK
file:
path: /tmp/JDK21.tar.gz
state: absent
when: jdk21_installed.rc != 0
tags: java
###########
# Ansible #
###########
- name: Check if Ansible is installed
shell: which ansible >/dev/null 2>&1
failed_when: false
register: ansible_installed
tags: ansible
- name: Add Ansible repository
apt_repository:
repo: ppa:ansible/ansible
when: ansible_installed.rc != 0
tags: ansible
- name: Install Ansible
apt:
name: ansible
update_cache: yes
when: ansible_installed.rc != 0
tags: ansible
#######
# Git #
#######
- name: Check if Git is installed
shell: git --version >/dev/null 2>&1
failed_when: false
register: git_installed
tags:
- skip_ansible_lint
- git
- name: Test if Git is installed at the correct version
shell: git --version | sed -e 's/git version //g' | awk -F'[.]' '{print $1 "." $2}'
when: git_installed.rc == 0
register: git_version
tags:
- skip_ansible_lint
- git
- name: Download Git Source
get_url:
url: https://www.kernel.org/pub/software/scm/git/git-2.15.0.tar.xz
dest: /tmp/git-2.15.0.tar.xz
mode: 0440
checksum: sha256:107116489f10b758b51af1c5dbdb9a274917b0fb67dc8eaefcdabc7bc3eb3e6a
when:
- (git_installed.rc != 0 ) or (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt'))
tags: git
- name: Extract Git Source
unarchive:
src: /tmp/git-2.15.0.tar.xz
dest: /tmp/
copy: False
when:
- (git_installed.rc != 0 ) or (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt'))
tags: git
- name: Compile and Install Git from Source
shell: cd /tmp/git-2.15.0 && ./configure --prefix=/usr/local --without-tcltk && make clean && make -j {{ ansible_processor_vcpus }} && sudo make install
become: yes
when:
- (git_installed.rc != 0 ) or (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt'))
tags: git
- name: Remove system git if needed
apt:
name: git
state: absent
when:
- (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt'))
tags: git
- name: Symlink git to /usr/bin/git
file:
src: /tmp/git-2.15.0/git
dest: /usr/bin/git
state: link
when:
- (git_installed.rc != 0 ) or (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt'))
tags: git
###########
# Vagrant #
###########
- name: Check if Vagrant is installed
shell: which vagrant >/dev/null 2>&1
failed_when: false
register: vagrant_installed
tags: vagrant
- name: Test if the Vagrant version is >2.1
shell: vagrant --version | sed -e 's/Vagrant //g' | awk -F'[.]' '{print $1 "." $2 "." $3}'
when: vagrant_installed.rc == 0
register: vagrant_version
tags: vagrant
- name: Download and add the HashiCorp GPG key
ansible.builtin.get_url:
url: https://apt.releases.hashicorp.com/gpg
dest: /tmp/hashicorp.gpg
when:
- (vagrant_installed.rc != 0) or (vagrant_installed.rc == 0 and vagrant_version.stdout is version_compare('2.2.19', operator='lt'))
tags: vagrant
- name: Add the HashiCorp GPG key to the keyring
ansible.builtin.command:
cmd: gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg /tmp/hashicorp.gpg
creates: /usr/share/keyrings/hashicorp-archive-keyring.gpg
when:
- (vagrant_installed.rc != 0) or (vagrant_installed.rc == 0 and vagrant_version.stdout is version_compare('2.2.19', operator='lt'))
tags: vagrant
- name: Add the HashiCorp repository
ansible.builtin.command:
cmd: echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/hashicorp.list
creates: /etc/apt/sources.list.d/hashicorp.list
when:
- (vagrant_installed.rc != 0) or (vagrant_installed.rc == 0 and vagrant_version.stdout is version_compare('2.2.19', operator='lt'))
tags: vagrant
- name: Update apt package index
ansible.builtin.apt:
update_cache: yes
- name: Install Vagrant
ansible.builtin.apt:
name: vagrant
state: present
when:
- (vagrant_installed.rc != 0) or (vagrant_installed.rc == 0 and vagrant_version.stdout is version_compare('2.2.19', operator='lt'))
tags: vagrant
- name: Install Vagrant Plugins For WinRM
ansible.builtin.apt:
name: vagrant
state: present
when:
- (vagrant_installed.rc != 0) or (vagrant_installed.rc == 0 and vagrant_version.stdout is version_compare('2.2.19', operator='lt'))
tags: vagrant
##############
# VirtualBox #
##############
- name: Update apt cache
apt:
update_cache: yes
- name: Check if Virtualbox is installed
shell: which virtualbox >/dev/null 2>&1
failed_when: false
register: virtualbox_installed
tags: VBox
- name: Import GPG keys
apt_key:
url: "{{ item }}"
state: present
with_items:
- https://www.virtualbox.org/download/oracle_vbox_2016.asc
- https://www.virtualbox.org/download/oracle_vbox.asc
when: virtualbox_installed.rc != 0
tags: VBox
- name: Add Virtualbox Repository
apt_repository:
repo: deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian bionic contrib
when: virtualbox_installed.rc != 0
tags: VBox
- name: Update apt cache Again
apt:
update_cache: yes
when: virtualbox_installed.rc != 0
- name: Install linux headers and dkms
apt:
name:
- "linux-headers-{{ ansible_kernel }}"
- dkms
state: present
when: virtualbox_installed.rc != 0
tags: VBox
- name: Install VirtualBox
apt:
name: "virtualbox"
state: present
when: virtualbox_installed.rc != 0
tags: VBox
##########
# QEMU #
##########
- name: Install QEMU Packages
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- qemu-kvm
- virt-manager
- virtinst
- libvirt-clients
- bridge-utils
- libvirt-daemon-system
- qemu-system-x86
- qemu-system-s390x
- qemu-system-ppc
- qemu-system-arm
- qemu-system-misc
tags: QEMU
################
# Jenkins_User #
################
- name: Set Home Folder for Jenkins user
set_fact:
home_folder: /home/{{ Jenkins_Username }}
tags: jenkins_user
- name: Create Jenkins user
action: user name={{ Jenkins_Username }} state=present home={{ home_folder }} shell=/bin/bash
failed_when: false
tags: jenkins_user
- name: Create Jenkins SSH Folder
file:
path: "{{ home_folder }}/.ssh"
state: directory
owner: "{{ Jenkins_Username }}"
group: "{{ Jenkins_Username }}"
mode: '0700'
tags: jenkins_user
- name: Add github.com to known_hosts
known_hosts:
name: github.com
key: github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
path: "{{ home_folder }}/.ssh/known_hosts"
state: present
tags: jenkins_user
- name: Change ownership of jenkins' ~/.ssh/known_hosts
file:
path: "{{ home_folder }}/.ssh/known_hosts"
owner: "{{ Jenkins_Username }}"
mode: 0644
tags: jenkins_user
- name: Add Jenkins user to the audio group
user: name={{ Jenkins_Username }}
groups=audio
append=yes
tags: jenkins_user
- name: Set authorized key for Jenkins user
authorized_key:
user: "{{ Jenkins_Username }}"
state: present
key: "{{ Jenkins_User_SSHKey }}"
tags: jenkins_user
- name: Pip install winrm modules
pip:
executable: /usr/bin/pip
name: ["requests-credssp", "pywinrm"]
become: yes
become_user: "{{ Jenkins_Username }}"
tags: jenkins_user
####################################
# Vagrant Plugins For Jenkins User #
####################################
## Vagrant Plugins Are User Specific, So Install As Jenkins User
- name: Install Vagrant plugin winrm
command: vagrant plugin install winrm
register: winrm_installed
changed_when: "'installed' in winrm_installed.stdout"
failed_when: winrm_installed.rc != 0 and "'already installed' not in winrm_installed.stdout"
ignore_errors: yes
become: yes
become_user: "{{ Jenkins_Username }}"
- name: Install Vagrant plugin winrmfs
command: vagrant plugin install winrm-fs
register: winrmfs_installed
changed_when: "'installed' in winrmfs_installed.stdout"
failed_when: winrmfs_installed.rc != 0 and "'already installed' not in winrmfs_installed.stdout"
ignore_errors: yes
become: yes
become_user: "{{ Jenkins_Username }}"
- name: Install Vagrant plugin winrm-elevated
command: vagrant plugin install winrm-elevated
register: winrmelevate_installed
changed_when: "'installed' in winrmelevate_installed.stdout"
failed_when: winrmelevate_installed.rc != 0 and "'already installed' not in winrmelevate_installed.stdout"
ignore_errors: yes
become: yes
become_user: "{{ Jenkins_Username }}"
- name: Install Vagrant plugin vagrant-disksize
command: vagrant plugin install vagrant-disksize
register: disksize_installed
changed_when: "'installed' in disksize_installed.stdout"
failed_when: disksize_installed.rc != 0 and "'already installed' not in disksize_installed.stdout"
ignore_errors: yes
become: yes
become_user: "{{ Jenkins_Username }}"
- name: Ensure all plugins are installed
fail:
msg: "Failed to install Vagrant plugins"
when: winrm_installed.failed or winrmfs_installed.failed or winrmelevate_installed.failed or disksize_installed.failed
- name: Output installation results
debug:
msg: >
winrm plugin installation: {{ winrm_installed.stdout }}
winrmfs plugin installation: {{ winrmfs_installed.stdout }}
winrm-elevated plugin installation: {{ winrmelevate_installed.stdout }}
vagrant-disksize plugin installation: {{ disksize_installed.stdout }}