Ansible:如何通知python脚本有关任务的结果?

我有简单的手册来从共享中获取和复制文件到远程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.

相关文章

----name:setpublickeyonremotehosts&setreomtehostssud...
环境准备#cat/etcedhat-releaseCentOSLinuxrelease7.9.2009(...
准备好环境,在安装之前请先了解openshift提供的ansible有大...
Ansible:运维工作:系统安装(物理机、虚拟机)-->程序包...
ansible与salt对比相同都是为了同时在多台机器上执行相同的命...
[root@node1playbook]#catnginx.yml-hosts:test\\主...