I am trying to write a ansible playbook and these are the overview.
java -version
java --fullversion
I need to determine what target machine has what Java installed or NOT installed.
That's Pretty much everything.
This is what i wrote but this once only gives me java version. Thank you for your help.
- hosts: localhost
gather_facts: False
tasks:
- name: Fetch Java version
shell: java -version 2>&1 | grep version | awk '{print $3}' | sed 's/"//g'
changed_when: False
register: java_result
- debug:
msg: "{{ java_result.stdout }}"```
When you have no Java, your shell will fail. You can check this.
- hosts: localhost
gather_facts: False
tasks:
- name: Fetch Java version
shell: java -version 2>&1 | grep version | awk '{print $3}' | sed 's/"//g'
changed_when: False
register: java_result
failed_when: false
- debug: msg=No Java or something failed.
when: java_result.rc!=0
- debug:
msg: "{{ java_result.stdout }}"```
when: java_result.rc==0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.