Ansible:Pbrun 无法执行

Ansible:Pbrun 无法执行

我有以下库存文件

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

和剧本文件

---
- 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

现在,当我运行 ansible playbook 时,它会连接到 ssh 主机,并且能够java -version ..成功运行命令,但无法mv按需要运行命令pbrun

当我become: true从剧本中删除时,它显示权限错误

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

当我不删除become: true它时,它会出现其他错误,而且它也无法正常工作

答案1

我没有看到您设置了become_method: pbrun任何地方。这是必需的。

答案2

我找到的解决方案如下

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

当我们运行 pbrun sa -u root 时

也不要忘记设置ansible_become_pass到库存文件中或--ask-become-pass

谢谢

相关内容