第一playbook.yml:
---
- hosts: all
tasks:
- name: test
shell: chdir=/home/tibco pbrun su - tibco sh test.sh
sudo: yes
错误:
[root@c0043724 ansible]# ansible-playbook -vvv first-playbook.yml -u balp --ask-pass -c paramiko
SSH password:
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
<c0043725.itcs.hp.com> ESTABLISH CONNECTION FOR USER: balp on PORT 22 TO c0043725.itcs.hp.com
<c0043725.itcs.hp.com> REMOTE_MODULE setup
<c0043725.itcs.hp.com> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1426531409.47-88648204897709 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1426531409.47-88648204897709 && echo $HOME/.ansible/tmp/ansible-tmp-1426531409.47-88648204897709'
<c0043725.itcs.hp.com> PUT /tmp/tmpNP2qY2 TO /home/balp/.ansible/tmp/ansible-tmp-1426531409.47-88648204897709/setup
<c0043725.itcs.hp.com> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/balp/.ansible/tmp/ansible-tmp-1426531409.47-88648204897709/setup; rm -rf /home/balp/.ansible/tmp/ansible-tmp-1426531409.47-88648204897709/ >/dev/null 2>&1'
ok: [c0043725.itcs.hp.com]
TASK: [test] ******************************************************************
<c0043725.itcs.hp.com> ESTABLISH CONNECTION FOR USER: balp on PORT 22 TO c0043725.itcs.hp.com
<c0043725.itcs.hp.com> REMOTE_MODULE command chdir=/home/tibco pbrun su - tibco sh test.sh #USE_SHELL
<c0043725.itcs.hp.com> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1426531412.61-87821666758998 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1426531412.61-87821666758998 && echo $HOME/.ansible/tmp/ansible-tmp-1426531412.61-87821666758998'
<c0043725.itcs.hp.com> PUT /tmp/tmpNgfy06 TO /home/balp/.ansible/tmp/ansible-tmp-1426531412.61-87821666758998/command
<c0043725.itcs.hp.com> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=torjbeltprhcmjkqbwcakmroqrxvfiai] password: " -u root /bin/sh -c "echo BECOME-SUCCESS-torjbeltprhcmjkqbwcakmroqrxvfiai; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/balp/.ansible/tmp/ansible-tmp-1426531412.61-87821666758998/command; rm -rf /home/balp/.ansible/tmp/ansible-tmp-1426531412.61-87821666758998/ >/dev/null 2>&1"'
failed: [c0043725.itcs.hp.com] => {"changed": true, "cmd": "pbrun su - tibco sh test.sh", "delta": "0:00:00.024944", "end": "2015-03-16 18:43:33.371752", "rc": 127, "start": "2015-03-16 18:43:33.346808", "warnings": []}
stderr: /bin/sh: pbrun: command not found
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/root/first-playbook.retry
c0043725.itcs.hp.com : ok=1 changed=0 unreachable=0 failed=1
你能帮忙解决一下吗?
答案 0 :(得分:0)
需要更多信息以便更好地进行调试。但我的猜测是你试图混合使用3种不同的做法。
su
在您正在执行的命令中。sudo: yes
root
,默认情况下会以root身份隐式连接到远程计算机(除非你在配置或清单中的某处覆盖它)渲染sudo
首先是不必要的)我建议你在剧本中使用pbrun
和test.sh
的完整路径,只保留一种方法来完成三个中的su
。
- 编辑 -
我假设您已经知道ansible.cfg
中的abtsudo_exe
参数
# change this for alternative sudo implementations
sudo_exe = sudo