Either you can set/edit default PATH for java bin in /etc/sudoers (visudo)
by editing
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Or you can set environment while executing ansible-playbook
---
- name: "checking the java version"
hosts: host
remote_user: myremoteuser
gather_facts: False
environment:
PATH: '$PATH:/path/to/bin/for/java'
become: True
become_user: serveruser
become_method: 'sudo'
Also, try to figure out if you can utilise become_flags option if above one
doesn't help.
On Tuesday, January 22, 2019 at 8:35:06 PM 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/72dc57f6-327f-4182-a8d8-7b69c2e64239%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.