0

I have the below inventory file

[server]
abc.com
[server:vars]
ansible_user="user1"
ansible_ssh_pass="pwd"
ansible_pbrun_exe="pbrun"
ansible_pbrun_password="pqa"
ansible_pbrun_user="root"

and the playbook file

---
- name: Upgrade Java Version to all the hosts
  hosts: all
  tasks:
    - name: run simple command
      shell: java -version 2>&1 | grep version | awk '{print $3}' | sed 's/"//g'
      register: javav
      
    - name: remove the currently installed java
      become: true
      become_method: "pbrun"
      shell: |
        mv /usr/bin/java  ~/bckup_java_exe
        mv /usr/java/ ~/bckup_java

Now when I run the ansible playbook it connects to the ssh host and is also able to run the java -version .. command successfully but not able to run the mv command as it needs pbrun

when I remove become: true from playbook it shows Permission error

```
: Permission denied", "mv: cannot move `/usr/java/' to
````

And when I do not remove become: true it gives some other error, and it is not working either

Rajarshi Das
  • 113
  • 6

2 Answers2

1

I do not see that you have set become_method: pbrun anywhere. This is required.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
0

The solution i have found is below

  become: "yes"
  become_method: "pbrun"
  become_user: "root"
  become_flags: "sa"

as we ran pbrun sa -u root

also do not forget to set ansible_become_pass into inventory file or --ask-become-pass

thanks

Rajarshi Das
  • 113
  • 6