我有简单的手册来从共享中获取和复制文件到远程Windows客户端:
- name: Test chocolatey module
hosts: win_clones
vars_files:
- /fullpath/hosts_vars
tasks:
- name: Fetching and copying the file on the client ...
win_get_url:
url: 'ftp://172.20.0.5/choco-repo/{{ item }}'
dest: 'C:\Test\{{ item }}'
with_items: "{{ clients[machine].to_install }}"
我使用子进程从python脚本运行此游戏:
for i in clients:
machine = "machine="
limit = "--limit="
an2 = subprocess.Popen(["ansible-playbook", "fetch.yml","-e", machine+i, limit+i], cwd='/home/diego/work/gitl_repo/ansible-software-deployment')
an2.wait()
当任务因任何原因失败时,我可以在终端中看到:
TASK [Fetching and copying the file on the client ...] *************************
Failed: [cl1] (item=banana) => {"Failed": true, "item": "banana", "msg": "Error downloading ftp://172.20.0.5/.....
是否可以将此信息传递给我的python脚本?换句话说,我怎么能告诉python某个任务的结果,即它是否失败或是否通过.谢谢
解决方法:
您可以通过configuration文件或env变量ANSIBLE_STDOUT_CALLBACK设置stdout_callback = json.
ansible-playbook将打印带有执行结果的巨大json文件到stdout.