# trying to make a java install idempotent

**URL:** <https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900>\
**Category:** Ansible Project\
**Created:** [June 3, 2013, 6:18pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900 "2013-06-03T18:18:18Z")\
**Posts on this page:** 8\
**Page:** 1

<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:** [June 3, 2013, 6:18pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900/1 "2013-06-03T18:18:18Z")

</div>

Hi lis,

I’m installing a specific version of java binar that is been executed every time I run the playbook, I’m trying to include a check to repeat the installation steps only if java is not installed :

# playbook :

- name: register if java is installed  
shell: rpm -qa | grep jdk  
register: java\_version

- name: downloading java binary from s3  
shell: /usr/bin/s3cmd get s3://my-bucket/packages/jdk-$JDK\_VERSION-linux-x64-rpm.bin --force  
when\_string: $java\_version != ‘jdk-1.6.0\_26-fcs.x86\_64’  
tags:

- java

- name: Installing Java  
shell: yes | ./jdk-\*-linux-x64-rpm.bin  
when\_string: $java\_version != ‘jdk-1.6.0\_26-fcs.x86\_64’  
tags:

- java

The above is not working as it will always run anyway and I’m not able to see what is the value of java\_version registered when running in verbose mode.. can you please advise ?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 3, 2013, 6:37pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900/2 "2013-06-03T18:37:26Z")

</div>

you will want ${java\_version.stdout}

---

<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:** [June 3, 2013, 6:39pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900/3 "2013-06-03T18:39:45Z")

</div>

tried that as well with no luck.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [June 3, 2013, 6:42pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900/4 "2013-06-03T18:42:19Z")

</div>

Insufficient data.

How about sharing the output of -v mode?

---

<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:** [June 3, 2013, 6:45pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900/5 "2013-06-03T18:45:46Z")

</div>

got it working, I was running the playbook limited to the tag java but didn’t had tagged the register action.

Thank you.

---

<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:** [June 3, 2013, 7:10pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900/6 "2013-06-03T19:10:35Z")

</div>

I’m still having problems with this, here is the current playbook :

- name: register if java version jdk-1.6.0\_26-fcs.x86\_64 is installed  
shell: rpm -qa | grep jdk  
register: java\_version

- name: downloading java binary from s3  
shell: /usr/bin/s3cmd get s3://my-bucket/packages/jdk-$JDK\_VERSION-linux-x64-rpm.bin --force  
when\_string: ${java\_version.stdout} != ‘jdk-1.6.0\_26-fcs.x86\_64’  
tags:

- java

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

- java

- name: Installing Java  
shell: yes | ./jdk-\*-linux-x64-rpm.bin  
when\_string: ${java\_version.stdout} != ‘jdk-1.6.0\_26-fcs.x86\_64’  
tags:

- java

Now when I run this on a new system where java is not installed I get the following error :

TASK: [register if java version jdk-1.6.0\_26-fcs.x86\_64 is installed] \*\*\*\*\*\*\*\*\*  
\<[ec2-54-216-109-202.eu-west-1.compute.amazonaws.com](http://ec2-54-216-109-202.eu-west-1.compute.amazonaws.com)\> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO [ec2-54-216-109-202.eu-west-1.compute.amazonaws.com](http://ec2-54-216-109-202.eu-west-1.compute.amazonaws.com)  
\<[ec2-54-216-109-202.eu-west-1.compute.amazonaws.com](http://ec2-54-216-109-202.eu-west-1.compute.amazonaws.com)\> EXEC /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1370286578.55-137483020064325 && echo $HOME/.ansible/tmp/ansible-1370286578.55-137483020064325’  
\<[ec2-54-216-109-202.eu-west-1.compute.amazonaws.com](http://ec2-54-216-109-202.eu-west-1.compute.amazonaws.com)\> REMOTE\_MODULE command rpm -qa | grep jdk #USE\_SHELL  
\<[ec2-54-216-109-202.eu-west-1.compute.amazonaws.com](http://ec2-54-216-109-202.eu-west-1.compute.amazonaws.com)\> PUT /tmp/tmpQUg6PG TO /root/.ansible/tmp/ansible-1370286578.55-137483020064325/command  
\<[ec2-54-216-109-202.eu-west-1.compute.amazonaws.com](http://ec2-54-216-109-202.eu-west-1.compute.amazonaws.com)\> EXEC /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=frdomsgzrbjwktqrwxxndujoxmfffyjb] password: " -u root /bin/sh -c '”’“‘/usr/bin/python /root/.ansible/tmp/ansible-1370286578.55-137483020064325/command; rm -rf /root/.ansible/tmp/ansible-1370286578.55-137483020064325/ \>/dev/null 2\>&1’”‘"’’  
failed: [[ec2-54-216-109-202.eu-west-1.compute.amazonaws.com](http://ec2-54-216-109-202.eu-west-1.compute.amazonaws.com)] =\> {“changed”: true, “cmd”: "rpm -qa | grep jdk ", “delta”: “0:00:00.326476”, “end”: “2013-06-03 19:09:39.251702”, “item”: “”, “rc”: 1, “start”: “2013-06-03 19:09:38.925226”}

FATAL: all hosts have already failed – aborting

---

<div class="post-metadata">

**Author:** ![Edgars](https://avatars.discourse-cdn.com/v4/letter/e/f17d59/32.png) [@Edgars](https://forum.ansible.com/u/Edgars)\
**Post date:** [June 3, 2013, 8:24pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900/7 "2013-06-03T20:24:13Z")

</div>

This is fine. Since you don’t have jdk installed, your “rpm -qa | grep jdk” returns status code 1 (because that command did not return any output). You can check it by executing “rpm -qa | grep jdk; echo $?” in your console.

Use ignore\_errors = True in your task where you check jdk version and you should be fine

Edgars

---

<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:** [June 3, 2013, 9:00pm UTC](https://forum.ansible.com/t/trying-to-make-a-java-install-idempotent/12900/8 "2013-06-03T21:00:14Z")

</div>

Thanks Edgars, I know the return status is 1 but a false status should actually be treated as an error…

I was hoping to be able to handle this in a more “clean” fashion but for now using ignore\_errors is ok.

Regards,  
N.
