first-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
你能帮忙解决吗?
最佳答案
需要更多信息以进行更好的调试。但是我的猜测是您正在尝试混合使用su的3种不同方法。
一些名为pbrun的自定义工具(我猜这是您/您的ops ppl创建的一些脚本,以允许您sudo访问)。
您正在执行的命令中的su
。
您通过指定sudo: yes
来询问ansible su。
(更不用说您以root
的身份运行剧本了,默认情况下,它将以root身份隐式连接到远程计算机(除非您在配置或清单中的某处覆盖了它)首先使sudo
成为不必要的内容)
我建议您在剧本中使用pbrun
和test.sh
的完整路径,并且仅保留执行这三种方法中的su
的一种方法。
-编辑-
我假设您已经知道ansible.cfg中的abt sudo_exe
参数
# change this for alternative sudo implementations
sudo_exe = sudo
关于linux - Pbrun无法正常运行的剧本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29084637/