Installing Oracle Java is not straight forward because it is not delivered via Apt or in an RPM.
I have written a role, "java", that does this work and I want to be able to detect that Java is already installed when this role is requested subsequently so that I do not run its steps.
What is the best practice approach to indicate that "Java is already installed"?
I can see putting a marker file somewhere - such as /etc/java-version and the contents would have the version number and then the role steps could have a conditional looking for this marker. However, this approach does not seem very elegant.
Suggestions for a best practices solution for this?
I would worry that someone will delete /etc/java-version one day and blow everything up.
Could you attempt to actually run something like shell: “java --version” and then register the output to a variable? You could then put a when on the java role that checks the contents of the output, possibly even for a certain version.
I had the same case but couldn’t find an RPM version besides the java openjdk which is not suitable for our application, this is the tasks I’m using in Ansible to install Java jdk-1.6.0_26-fcs.x86_64 version downloaded from Oracle and saved in a S3 bucket :
“”"
name: register if java version jdk-1.6.0_26-fcs.x86_64 is installed
shell: rpm -qa | grep jdk
register: java_version
ignore_errors: yes