Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

Commit d7d34d3

Browse files
authored
Merge pull request #9 from frieder/issue-7
Updated unarchive task, removed force install option, updated readme
2 parents 6d13e8c + 37fd894 commit d7d34d3

File tree

7 files changed

+57
-102
lines changed

7 files changed

+57
-102
lines changed

README.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ All role variables are defined in `defaults/main.yml`. One can overwrite these v
5959
| oraclejdk_license_accept | false | When installing a JDK this must be set to true otherwise the play will fail. Not required when removing a JDK. |
6060
| oraclejdk_state | present | Defines whether to add or remove a JDK from the target host. Possible values are `[present,absent]`. |
6161
| oraclejdk_cleanup | true | Remove all temp files/folders (both local and remote) after installation. When set to true this will result in "changed" plays. |
62-
| oraclejdk_force_install | false | By default the role will check if the JDK installation folder already exists and skips the extraction of the archive if it does exist. Setting this value to true will force the role to extract the archive even when the folder already exists. Please be aware that this may overwrite any previously made changes (e. g. JCE policy files). |
6362
| oraclejdk_dl_dir | /tmp/oraclejdk | The folder (both local and remote) to which the archives get downloaded/copied/extracted. |
6463
| oraclejdk_home | | The Java home directory to which the JDK should get extracted to and to which JAVA_HOME will point to if set. |
6564
| oraclejdk_profile_file | /etc/profile.d/java.sh | The file in which the role will set the JAVA_HOME and PATH export. |
@@ -79,6 +78,37 @@ All role variables are defined in `defaults/main.yml`. One can overwrite these v
7978
8079
Following are some examples how to use this role in an Ansible playbook.
8180
81+
**JDK8 & JDK9 together, set home for JDK8, update alternatives for both JDKs with different priorities**
82+
```yaml
83+
- hosts: jdk
84+
pre_tasks:
85+
- name: Install required packages (127.0.0.1)
86+
delegate_to: 127.0.0.1
87+
package:
88+
name: '{{ item }}'
89+
state: present
90+
with_items:
91+
- tar
92+
- unzip
93+
roles:
94+
- role: frieder.oraclejdk
95+
oraclejdk_license_accept: true
96+
oraclejdk_home: /opt/java/jdk9.0.1
97+
oraclejdk_sethome: false
98+
oraclejdk_alternative_prio: 100
99+
oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz'
100+
oraclejdk_checksum: 'sha256:2cdaf0ff92d0829b510edd883a4ac8322c02f2fc1beae95d048b6716076bc014'
101+
- role: frieder.oraclejdk
102+
oraclejdk_license_accept: true
103+
oraclejdk_home: /opt/java/jdk8u151
104+
oraclejdk_alternative_prio: 200
105+
oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz'
106+
oraclejdk_checksum: 'sha256:c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f'
107+
oraclejdk_jce_install: true
108+
oraclejdk_jce_url: 'http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip'
109+
oraclejdk_jce_checksum: 'sha256:f3020a3922efd6626c2fff45695d527f34a8020e938a49292561f18ad1320b59'
110+
```
111+
82112
**JDK8 w/ minimal configuration**
83113
```yaml
84114
- hosts: jdk8
@@ -93,14 +123,6 @@ Following are some examples how to use this role in an Ansible playbook.
93123
**JDK8 w/ JCE**
94124
```yaml
95125
- hosts: jdk8
96-
pre_tasks:
97-
- name: install required packages
98-
package:
99-
name: '{{ item }}'
100-
state: present
101-
with_items:
102-
- tar
103-
- unzip
104126
roles:
105127
- role: frieder.oraclejdk
106128
oraclejdk_license_accept: true
@@ -115,19 +137,10 @@ Following are some examples how to use this role in an Ansible playbook.
115137
**JDK8 full config**
116138
```yaml
117139
- hosts: jdk8
118-
pre_tasks:
119-
- name: install required packages
120-
package:
121-
name: '{{ item }}'
122-
state: present
123-
with_items:
124-
- tar
125-
- unzip
126140
roles:
127141
- role: frieder.oraclejdk
128142
oraclejdk_license_accept: true
129143
oraclejdk_cleanup: true
130-
oraclejdk_force_install: true
131144
oraclejdk_dl_dir: /tmp/java_download
132145
oraclejdk_home: /opt/java/java-8-151
133146
oraclejdk_sethome: true
@@ -183,10 +196,9 @@ Following are some examples how to use this role in an Ansible playbook.
183196
oraclejdk_home: /opt/java/jdk9.0.1
184197
oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz'
185198
oraclejdk_checksum: ''
186-
187-
- hosts: jdk9
188-
roles:
189199
- role: frieder.oraclejdk
190200
oraclejdk_state: absent
191201
oraclejdk_home: /opt/java/jdk9.0.1
192202
```
203+
204+

defaults/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#
55
oraclejdk_license_accept: false # must be set to true otherwise the play will fail
66
oraclejdk_cleanup: true # will remove temp files <--> plabooks will return changed = true if true
7-
oraclejdk_force_install: false # will install the JDK even when its already installed (dir exist check)
87
oraclejdk_state: present
98

109
oraclejdk_dl_dir: /tmp/oraclejdk # temp directory in which the archives are stored

tasks/02_fetchjdk.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@
2222
set_fact:
2323
oraclejdk_dl_artefact_path: '{{ dl_result.dest }}'
2424

25-
- name: Get name of folder within JDK tar archive
26-
shell: "tar tf {{ oraclejdk_dl_artefact_path }} | awk -F/ '{print $1}' | uniq"
27-
args:
28-
warn: false
29-
register: dl_inspect
30-
changed_when: false
31-
32-
- name: Set fact 'oraclejdk_dl_artefact_name' to name of folder in JDK archive
33-
set_fact:
34-
oraclejdk_dl_artefact_name: '{{ dl_inspect.stdout }}'
35-
3625
tags:
3726
- oraclejdk
3827
- oraclejdk_download

tasks/04_installjdk.yml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,20 @@
1313
block:
1414

1515
- name: Copy and extract JDK archive
16-
when: java_home_check.stat.exists == false or oraclejdk_force_install
16+
when: java_home_check.stat.exists == false
1717
block:
1818

19-
- name: 'Create temp directory at {{ oraclejdk_dl_dir }}'
20-
file:
21-
path: '{{ oraclejdk_dl_dir }}'
22-
state: directory
23-
24-
- name: 'Copy {{ oraclejdk_dl_artefact_path }} from source to target host'
25-
copy:
26-
src: '{{ oraclejdk_dl_artefact_path }}'
27-
dest: '{{ oraclejdk_dl_artefact_path }}'
28-
2919
- name: 'Create JDK base root directory at {{ oraclejdk_home }}'
3020
file:
3121
path: '{{ oraclejdk_home }}'
3222
state: directory
3323

34-
- name: 'Extract JDK archive to {{ oraclejdk_home }}/{{ oraclejdk_dl_artefact_name }}'
24+
- name: 'Extract JDK archive to {{ oraclejdk_home }}'
3525
unarchive:
3626
src: '{{ oraclejdk_dl_artefact_path }}'
3727
dest: '{{ oraclejdk_home }}'
38-
remote_src: true
28+
extra_opts: ['--strip-components=1']
3929

40-
- name: Move JDK content & cleanup of obsolete folder
41-
shell: 'mv {{ oraclejdk_home }}/{{ oraclejdk_dl_artefact_name }}/* {{ oraclejdk_home }} && rmdir {{ oraclejdk_home }}/{{ oraclejdk_dl_artefact_name }}'
4230

4331
- name: Set JAVA_HOME
4432
when: oraclejdk_sethome

tasks/06_fetchjce.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
path: '{{ oraclejdk_home }}/conf/security/java.security'
66
register: jdk9_check
77

8+
- name: Check if JCE is already installed
9+
when: oraclejdk_jce_install
10+
shell: '{{ oraclejdk_home }}/bin/jrunscript -e "print (javax.crypto.Cipher.getMaxAllowedKeyLength(\"SHA256\") > 128);"'
11+
changed_when: false
12+
ignore_errors: true
13+
register: jce_installed
814

915
- name: Fetch Oracle Java Cryptography Extension (JCE) artefacts (JDK8 only)
10-
when: oraclejdk_jce_install and jdk9_check.stat.exists == false
16+
when: oraclejdk_jce_install and jce_installed.stdout == 'false' and jdk9_check.stat.exists == false
1117
delegate_to: 127.0.0.1
1218
run_once: true
1319
block:
@@ -24,6 +30,12 @@
2430
checksum: '{{ oraclejdk_jce_checksum }}'
2531
dest: '{{ oraclejdk_dl_dir }}/{{ oraclejdk_jce_name }}.zip'
2632

33+
- name: Unzip Oracle JCE archive (JDK8 only)
34+
unarchive:
35+
src: '{{ oraclejdk_dl_dir }}/{{ oraclejdk_jce_name }}.zip'
36+
dest: '{{ oraclejdk_dl_dir }}/'
37+
remote_src: true
38+
2739
tags:
2840
- oraclejdk
2941
- oraclejdk_jce

tasks/08_installjce.yml

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,17 @@
33
- name: JCE block
44
block:
55

6-
- name: Check if JCE is already installed
7-
when: oraclejdk_jce_install
8-
shell: '{{ oraclejdk_home }}/bin/jrunscript -e "print (javax.crypto.Cipher.getMaxAllowedKeyLength(\"SHA256\") > 128);"'
9-
changed_when: false
10-
ignore_errors: true
11-
register: jce_installed
12-
136
# JDK8
147
- name: Install Oracle Java Cryptography Extension (JDK8 only)
158
when: oraclejdk_jce_install and jce_installed.stdout == 'false' and jdk9_check.stat.exists == false
16-
block:
17-
18-
- name: 'Create temp directory at {{ oraclejdk_dl_dir }} (JDK8 only)'
19-
file:
20-
path: '{{ oraclejdk_dl_dir }}'
21-
state: directory
22-
23-
- name: 'Copy Oracle JCE archive to temp directory at {{ oraclejdk_dl_dir }} (JDK8 only)'
24-
copy:
25-
src: '{{ oraclejdk_dl_dir }}/{{ oraclejdk_jce_name }}.zip'
26-
dest: '{{ oraclejdk_dl_dir }}/{{ oraclejdk_jce_name }}.zip'
27-
28-
- name: Unzip Oracle JCE archive (JDK8 only)
29-
unarchive:
30-
src: '{{ oraclejdk_dl_dir }}/{{ oraclejdk_jce_name }}.zip'
31-
dest: '{{ oraclejdk_dl_dir }}/'
32-
remote_src: true
33-
34-
- name: Copy JCE policy files to JDK (JDK8 only)
35-
copy:
36-
src: '{{ oraclejdk_dl_dir }}/{{ oraclejdk_jce_name }}/{{ item }}'
37-
dest: '{{ oraclejdk_home }}/jre/lib/security/{{ item }}'
38-
remote_src: true
39-
with_items:
40-
- US_export_policy.jar
41-
- local_policy.jar
42-
43-
- name: Check if JCE has successfully been installed (JDK8 only)
44-
shell: '{{ oraclejdk_home }}/bin/jrunscript -e "print (javax.crypto.Cipher.getMaxAllowedKeyLength(\"SHA256\") > 128);"'
45-
changed_when: false
46-
ignore_errors: true
47-
register: jce_check
48-
49-
- name: Fail if JCE installation was not successful
50-
when: jce_check.stdout == 'false'
51-
fail:
52-
msg: JCE has not successfully been installed.
53-
54-
55-
# JDK9 (already enabled by default, only required to re-enable it)
9+
copy:
10+
src: '{{ oraclejdk_dl_dir }}/{{ oraclejdk_jce_name }}/{{ item }}'
11+
dest: '{{ oraclejdk_home }}/jre/lib/security/{{ item }}'
12+
with_items:
13+
- US_export_policy.jar
14+
- local_policy.jar
15+
16+
# JDK9
5617
- name: Enable unlimited Java Cryptography Extension key strength (JDK9 only)
5718
when: oraclejdk_jce_install and jce_installed.stdout == 'false' and jdk9_check.stat.exists == true
5819
lineinfile:
@@ -73,7 +34,6 @@
7334
fail:
7435
msg: JCE has not successfully been installed.
7536

76-
7737
tags:
7838
- oraclejdk
7939
- oraclejdk_jce

tasks/10_cleanup.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
path: '{{ oraclejdk_dl_dir }}'
1212
state: absent
1313

14-
- name: 'Remove temp folder at {{ oraclejdk_dl_dir }}'
15-
file:
16-
path: '{{ oraclejdk_dl_dir }}'
17-
state: absent
18-
1914
tags:
2015
- oraclejdk
2116
- oraclejdk_cleanup

0 commit comments

Comments
 (0)