From 9354f4e4832cf5a64ec4527b37f1587549b9f94a Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Tue, 30 Apr 2019 13:03:07 +0200 Subject: [PATCH] Check if a jdk is installed and set jdk_java_home accordingly. See https://support.d4science.org/issues/16607 --- smartgears/smartgears/tasks/main.yml | 1 + smartgears/smartgears/tasks/set_jdk_home.yml | 63 ++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 smartgears/smartgears/tasks/set_jdk_home.yml diff --git a/smartgears/smartgears/tasks/main.yml b/smartgears/smartgears/tasks/main.yml index 03191300..7434edbf 100644 --- a/smartgears/smartgears/tasks/main.yml +++ b/smartgears/smartgears/tasks/main.yml @@ -1,4 +1,5 @@ --- +- import_tasks: set_jdk_home.yml - import_tasks: smartgears-app.yml - import_tasks: data-transfer-service.yml when: data_transfer_service_install diff --git a/smartgears/smartgears/tasks/set_jdk_home.yml b/smartgears/smartgears/tasks/set_jdk_home.yml new file mode 100644 index 00000000..698cfd82 --- /dev/null +++ b/smartgears/smartgears/tasks/set_jdk_home.yml @@ -0,0 +1,63 @@ +--- +- block: + - name: Are we using the distribution OpenJDK? + stat: + path: /usr/lib/jvm/java-{{ openjdk_default }}-openjdk-amd64 + register: jdk_java_home_path + when: openjdk_default is defined + + - debug: + msg: 'The jdk java home is {{ jdk_java_home_path.stat.path }}' + when: jdk_java_home_path.stat.path is defined + + - name: Set the Java home when we are using the distribution OpenJDK + set_fact: + jdk_java_home: '{{ jdk_java_home_path.stat.path }}' + when: jdk_java_home_path.stat.isdir is defined and jdk_java_home_path.stat.isdir + + when: jdk_java_home is not defined + tags: [ 'smartgears', 'smartgears_distribution', 'tomcat' ] + +- block: + - name: Are we using the Zulu OpenJDK? + stat: + path: /usr/lib/jvm/zulu-{{ openjdk_default }}-amd64 + register: jdk_java_home_path + when: openjdk_default is defined + + - debug: + msg: 'The jdk java home is {{ jdk_java_home_path.stat.path }}' + when: jdk_java_home_path.stat.path is defined + + - name: Set the Java home when we are using the distribution OpenJDK + set_fact: + jdk_java_home: '{{ jdk_java_home_path.stat.path }}' + when: jdk_java_home_path.stat.isdir is defined and jdk_java_home_path.stat.isdir + + when: jdk_java_home is not defined + tags: [ 'smartgears', 'smartgears_distribution', 'tomcat' ] + +- block: + - name: Are we using the Oracle JDK? + stat: + path: /usr/lib/jvm/java-{{ jdk_default }}-oracle + register: jdk_java_home_path + when: openjdk_default is not defined + + - debug: + msg: 'The jdk java home is {{ jdk_java_home_path.stat.path }}' + when: jdk_java_home_path.stat.path is defined + + - name: Set the Java home when we are using the Oracle JDK + set_fact: + jdk_java_home: '{{ jdk_java_home_path.stat.path }}' + when: jdk_java_home_path.stat.isdir is defined and jdk_java_home_path.stat.isdir + + when: jdk_java_home is not defined + tags: [ 'smartgears', 'smartgears_distribution', 'tomcat' ] + +- name: Fail if we are not able to set the jdk_java_home variable + fail: + msg: 'No valid JDK installation found, failing!' + when: jdk_java_home is not defined + tags: [ 'smartgears', 'smartgears_distribution', 'tomcat' ]