gpt4 book ai didi

python - Ansible:如何将任务的结果通知 python 脚本?

转载 作者:太空宇宙 更新时间:2023-11-04 07:35:13 24 4
gpt4 key购买 nike

我有一个简单的剧本来从共享中获取文件并将其复制到远程 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 设置 stdout_callback = json文件或环境变量 ANSIBLE_STDOUT_CALLBACK
ansible-playbook 会将巨大的 json 文件和执行结果打印到标准输出。

关于python - Ansible:如何将任务的结果通知 python 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37719943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com