在playbook下面运行时出错。 python脚本在我的主人身上,我想让它在两个奴隶上运行。不知道出了什么问题。
luckee@zarvis:~/playbooks$ ansible-playbook runscript.yml
PLAY [droplets] ****************************************************************
TASK [setup] *******************************************************************
ok: [CentOS1]
ok: [CentOS2]
TASK [Run python script] *******************************************************
fatal: [CentOS1]: FAILED! => {"changed": false, "cmd": "/home/luckee/python/userfind.py", "failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}
fatal: [CentOS2]: FAILED! => {"changed": false, "cmd": "/home/luckee/python/userfind.py", "failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}
NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @runscript.retry
PLAY RECAP *********************************************************************
CentOS1 : ok=1 changed=0 unreachable=0 failed=1
CentOS2 : ok=1 changed=0 unreachable=0 failed=1
luckee@zarvis:~/playbooks$
这是剧本。
---
- hosts: droplets
remote_user: root
tasks:
- name: Run python script
command: /home/luckee/python/userfind.py
...
期待您的帮助!
答案 0 :(得分:1)
您尝试在远程主机上执行本地文件。
如果您打算远程运行它,首先需要转移它或使用script module。它首先将文件传输到远程主机,然后执行它。
- name: Run python script
script: /home/luckee/python/userfind.py
如果您打算在本地运行脚本,请使用delegation:
- name: Run python script
command: /home/luckee/python/userfind.py
delegate_to: localhost
要显示任务的输出,首先需要register结果并使用debug任务打印出来。
- name: Any task
...
register: result
- name: Show result
debug: msg="{{ result.stdout }}"
答案 1 :(得分:0)
我认为首先需要将脚本传输到远程主机然后运行它:
---
- hosts: droplets
remote_user: root
tasks:
- name: copy the script to the remote host
copy:
src: userfind.py
dest: /tmp/userfind.py
mode: 0777
- name: Run python script
command: python /tmp/userfind.py
根据您的要求修复路径