
我有以下庫存文件
[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
謝謝