-
Notifications
You must be signed in to change notification settings - Fork 162
/
main.yml
150 lines (131 loc) · 4.76 KB
/
main.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
---
#
# installs java
#
- name: install add-apt-repostory
when: os == "ubuntu1404" and arch != "ppc64"
package: name=software-properties-common state=present
- name: add webupd8 oracle java repository
when: os == "ubuntu1404" and arch != "ppc64"
apt_repository: repo='ppa:webupd8team/java'
- name: add webupd8team oracle java repository
when: os == "debian8"
lineinfile:
dest: /etc/apt/sources.list
state: present
line: deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main
- name: add webupd8team oracle java repository key
when: os == "debian8"
shell: apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
- name: accept webupd8 oracle java 8 license
when: os == "ubuntu1404" and arch != "ppc64" or os == "debian8"
debconf: name='oracle-java8-installer' question='shared/accepted-oracle-license-v1-1' value='true' vtype='select'
# if this fails you want to check in vars/main.yml and add package name
# as appropriate -- try to use generic os family if available.
- name: Check if java is already installed
changed_when: no
check_mode: no
raw: "{{ java_path[os] | default(\"java\") }} -version"
register: java
ignore_errors: yes
- name: install java
when:
- java_package_name is defined and java_package_name != ""
- not os|startswith("zos")
- not os|startswith("macos")
notify:
- package updated
- restart Jenkins
package:
name: "{{ java_package_name }}"
state: latest
# Package manager mapping in ansible/roles/package-upgrade/vars/main.yml.
use: "{{ os|match_key(pm)|default(omit) }}"
- name: install java (macOS)
become_user: "{{ ansible_user }}"
when: java.rc > 0 and os|startswith("macos")
homebrew_cask:
name: "{{ java_package_name }}"
state: present
- name: install webupd8 oracle java 8 extras
when: java.rc > 0 and os == "ubuntu1404" and arch != "ppc64"
package: name="{{item}}" state=present
with_items:
- ca-certificates
- oracle-java8-set-default
# Uses the AdoptOpenJDK API https://github.com/adoptopenjdk/openjdk-api-v3
# to discover the most recent release for the given adoptopenjdk_version and
# platform.
- name: fetch adoptopenjdk metadata
check_mode: no
register: adoptopenjdk_metadata
uri:
body_format: json
return_content: yes
status_code: 200
url: "https://api.adoptopenjdk.net/v3/assets/feature_releases/{{ adoptopenjdk_version }}/ga?architecture={{ adoptopenjdk_arch }}&image_type=jre&jvm_impl=openj9&os={{ adoptopenjdk_os }}&project=jdk&heap_size=normal&page_size=1&sort_method=DEFAULT&sort_order=DESC&vendor=adoptopenjdk"
when: use_adoptopenjdk == True
# If we're already using the latest there is no need to do anything.
- name: check existing adoptopenjdk version is up to date
set_fact:
update_adoptopenjdk: "{{ adoptopenjdk_metadata.json[0].version_data.openjdk_version not in java.stdout }}"
when: use_adoptopenjdk == True
- name: create cache directory for adoptopenjdk binaries
file:
path: "/var/cache/adoptopenjdk-binaries"
state: directory
when:
- use_adoptopenjdk == True
- update_adoptopenjdk == True
- name: download adoptopenjdk binary
get_url:
checksum: sha256:{{ adoptopenjdk_package.checksum }}
dest: "/var/cache/adoptopenjdk-binaries/{{ adoptopenjdk_package.name }}"
url: "{{ adoptopenjdk_package.link }}"
register: adoptopenjdk_local
when:
- use_adoptopenjdk == True
- update_adoptopenjdk == True
vars:
adoptopenjdk_package: "{{ adoptopenjdk_metadata.json[0].binaries[0].package }}"
- name: unpack adoptopenjdk binary
register: adoptopenjdk_unpacked
unarchive:
dest: "/opt/"
list_files: yes
remote_src: yes
src: "{{ adoptopenjdk_local.dest }}"
when:
- use_adoptopenjdk == True
- update_adoptopenjdk == True
# Store the current state of the symlink before modifying.
- name: check existing adoptopenjdk symlink
register: adoptopenjdk_symlink
stat:
path: "/usr/bin/java"
when:
- use_adoptopenjdk == True
- update_adoptopenjdk == True
- name: symlink adoptopenjdk
file:
src: "/opt/{{ adoptopenjdk_unpacked.files[0].split('/')[0] }}/bin/java"
dest: "/usr/bin/java"
state: link
notify:
- restart Jenkins
when:
- use_adoptopenjdk == True
- update_adoptopenjdk == True
# If the symlink existed before we modified it, check if the old target matches
# the new target. If they do not match, remove the old JRE.
- name: remove old adoptopenjdk
file:
path: "{{ old_jdk_dir }}"
state: absent
vars:
old_jdk_dir: "{{ adoptopenjdk_symlink.stat.lnk_source | dirname | dirname }}"
when:
- use_adoptopenjdk == True
- update_adoptopenjdk == True
- adoptopenjdk_symlink.stat.exists
- adoptopenjdk_symlink.stat.lnk_source != "/opt/"+adoptopenjdk_unpacked.files[0].split('/')[0]+"/bin/java"