Ansible command to check the java version in different servers

I am writing a Test case using ansible.There are totally 9 servers in which I need to check whether the installed java version is 1.7.0 or not?

If it is less than 1.7.0 then test case should fail.

Can anyone help me to write this Test case as I am very new to ansible.

Thanks in advance

-------------Problems Reply------------

Altough in your question you havn't specified what have you tried, but still

You can run a commands like this

ansible your_host -m command -a 'java -version'

If you need to parse the output of java -version there is a very good script from Glenn Jackman here adapt it to your needs and use it.

If you are still looking for help, be more specific and show what you tried to do.

Ansible has a version_compare filter since 1.6. But since Ansible doesn't know about your Java version you first need to fetch it in a separate task and register the output, so you can compare it.

- name: Fetch Java version
shell: java -version 2>&1 | grep version | awk '{print $3}' | sed 's/"//g'
register: java_version

- assert:
- java_version.stdout | version_compare('1.6', '>=')

On a sidenote, if your main use case for Ansible is to validate the server state you might want to have a look at serverspec instead.

Category:unix Views:2 Time:2018-07-11

Related post

Copyright (C), All Rights Reserved.

processed in 0.139 (s). 11 q(s)