# Question about best practice approach to indicate that something is already "setup"

**URL:** <https://forum.ansible.com/t/question-about-best-practice-approach-to-indicate-that-something-is-already-setup/14325>\
**Category:** Ansible Project\
**Created:** [January 11, 2014, 10:48pm UTC](https://forum.ansible.com/t/question-about-best-practice-approach-to-indicate-that-something-is-already-setup/14325 "2014-01-11T22:48:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Randolph\_Kahle](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@Randolph\_Kahle](https://forum.ansible.com/u/Randolph_Kahle)\
**Post date:** [January 11, 2014, 10:48pm UTC](https://forum.ansible.com/t/question-about-best-practice-approach-to-indicate-that-something-is-already-setup/14325/1 "2014-01-11T22:48:09Z")

</div>

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?

Thank you!

Randy

---

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [January 13, 2014, 4:24pm UTC](https://forum.ansible.com/t/question-about-best-practice-approach-to-indicate-that-something-is-already-setup/14325/2 "2014-01-13T16:24:53Z")

</div>

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.

hth,  
Mark

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 13, 2014, 5:26pm UTC](https://forum.ansible.com/t/question-about-best-practice-approach-to-indicate-that-something-is-already-setup/14325/3 "2014-01-13T17:26:24Z")

</div>

For an “enterprise” scenario, the preferred approach (imo) is to automate packaging the jre as an rpm|deb or find a third party repo.

[https://github.com/ksyz/oracle-java-rpm](https://github.com/ksyz/oracle-java-rpm)

---

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [January 13, 2014, 6:27pm UTC](https://forum.ansible.com/t/question-about-best-practice-approach-to-indicate-that-something-is-already-setup/14325/4 "2014-01-13T18:27:52Z")

</div>

Hi Randy,

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

- name: downloading java binary from s3  
s3: bucket=mybucket object=packages/jdk-{{ JDK\_VERSION }}-linux-x64-rpm.bin dest={{ DOWNLOAD\_DIR }}/jdk-{{ JDK\_VERSION }}-linux-x64-rpm.bin mode=get aws\_access\_key={{ AWS\_ACCESS\_KEY\_ID }} aws\_secret\_key={{ AWS\_SECRET\_ACCESS\_KEY }}  
when: java\_version.stdout != “jdk-1.6.0\_26-fcs.x86\_64”

- name: making java binary executable  
file: dest={{ DOWNLOAD\_DIR }}/jdk-{{ JDK\_VERSION }}-linux-x64-rpm.bin mode=0544  
when: java\_version.stdout != ‘jdk-1.6.0\_26-fcs.x86\_64’

- name: Installing Java  
shell: yes | /bin/sh {{ DOWNLOAD\_DIR }}/jdk-{{ JDK\_VERSION }}-linux-x64-rpm.bin  
when: java\_version.stdout != ‘jdk-1.6.0\_26-fcs.x86\_64’  
“”"

Regards,  
Nicolas.

---

<div class="post-metadata">

**Author:** ![Randolph\_Kahle](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@Randolph\_Kahle](https://forum.ansible.com/u/Randolph_Kahle)\
**Post date:** [January 13, 2014, 8:45pm UTC](https://forum.ansible.com/t/question-about-best-practice-approach-to-indicate-that-something-is-already-setup/14325/5 "2014-01-13T20:45:41Z")

</div>

Thank you for the replies.

After some experimentation with the proper way to test for values using the “when:” construct, I came up with the following:

- name: Determine which version of Java is installed  
shell: java -version 2\>&1 | grep version | cut -d ’ ’ -f 3  
register: java\_version  
ignore\_errors: yes

- name: Copy Java 7u45 to compute instance  
copy:  
src=jdk-7u45-linux-x64.tar.gz  
dest=/home/{{ user }}/jdk-7u45-linux-x64.tar.gz  
owner={{ user }}  
group={{ user }}  
mode=600  
when: java\_version.stdout != ‘“1.7.0\_45”’

…

– Randy

Nicolas G wrote:
