trying to make a java install idempotent

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 ?

you will want ${java_version.stdout}

tried that as well with no luck.

Insufficient data.

How about sharing the output of -v mode?

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

Thank you.

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> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO ec2-54-216-109-202.eu-west-1.compute.amazonaws.com
<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> REMOTE_MODULE command rpm -qa | grep jdk #USE_SHELL
<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> 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] => {“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

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

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.