Ansible:如何通知python脚本有关任务的结果?
发布于 2021-01-29 15:02:50
我有一个简单的剧本,用于从共享中获取文件并将文件复制到远程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某个任务的结果,即它是否失败或是否通过。谢谢
关注者
0
被浏览
100