Make a list of possible places that a java executable might be, in order of
preference, and work through the list checking each location in turn. Or
use the shell command I gave you last week to search an entire directory
tree for java executables; checking a list of possible candidates will be a
lot faster though. When you find one, use that executable in future
commands. If you store the information with the host, you can skip the
search next time.

Regards, K.

On Mon, Jan 28, 2019 at 5:24 PM ruben melvin <[email protected]>
wrote:

> I am actually not supposed to add or set anything on that server as it is
> a production server. So setting environment is not an option for me.
> I just need to know the java version using ansible so that it will help me
> a lot in reducing the manual works of my teammates.
>
> I tried out using the below playbook with "java -version" instead of
> "which java" but this time also faced error.
>
> ---
> - name: "checking the java version"
>   hosts: host
>   remote_user: c5115061
>   gather_facts: False
>   become: yes
>   become_user: idmspp
>   become_method: 'sudo'
>
>   tasks:
>     - name: which java
>       shell: java -version
> #      args:
> #        executable: /usr/java/
>       register: java
>
>
>     - debug: msg="{{ java }}"
>
>
> FAILED! => {"changed": true, "cmd": "java -version", "delta":
> "0:00:00.074380", "end": "2019-01-28 06:00:14.656299", "msg": "non-zero
> return code", "rc": 127, "start": "2019-01-28 06:00:14.581919", "stderr":
> "/bin/bash: java: command not found", "stderr_lines": ["/bin/bash: java:
> command not found"], "stdout": "", "stdout_lines": []}
>
>
> Can anyone help me in this?
>
> Thanks,
> Ruben
>
> On Tuesday, 22 January 2019 20:35:06 UTC+5:30, ruben melvin wrote:
>>
>> Hi guys,
>>
>> I am trying to execute below ansible playbook.
>>
>> ---
>> - name: "checking the java version"
>>   hosts: host
>>   remote_user: myremoteuser
>>   gather_facts: False
>>   become: yes
>>   become_user: serveruser
>>   become_method: 'sudo'
>>
>>   tasks:
>>     - name: which java
>>       shell: which java
>>       args:
>>         executable: /usr/java/
>>       register: java
>>
>>
>>     - debug: msg="{{ java }}"
>> ...
>>
>>
>> and getting the below error.
>>
>> FAILED! => {"changed": false, "cmd": "/usr/java/ -c 'which java'", "msg":
>> "[Errno 13] Permission denied", "rc": 13}
>>
>>
>> this is what I execute..
>>
>>
>> ansible-playbook -i hosts java.yml -vv --ask-become-pass
>>
>>
>> I will have to login first using "myremoteuser" and then I have to
>> change the user to "serveruser" and execute the above command.
>>
>> I am able to do this directly on server but not through ansible.
>>
>>
>> Kindly help.
>>
>>
>> Thanks in advance,
>>
>> Ruben
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/49dd72ca-39cc-4b49-afc7-8175ae380dc9%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/49dd72ca-39cc-4b49-afc7-8175ae380dc9%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Karl Auer

Email  : [email protected]
Website: http://2pisoftware.com

GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2B%2BT08QMZCZGP%2Bd8F64QKzcD4-HRpW%3DKN%3Dimxabt6c_RhXPG5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to