Ansible combine 'setup' output with task output to JSON

Viewed 4190

I currently gather facts about all my hosts using this command:

 ansible all -m setup --tree out

This creates a file for each host in the directory out with all the ansible variables in JSON format. Very useful.

However, my hosts consist of a lot of KVM hosts, so I want to add the output of virt / list_vms to each output.

I created a small playbook:

hosts: myhost

tasks:
  - name: VM list checker
    virt:
        name: list the VMs
        command: list_vms

I run this playbook like this:

ansible-playbook -v status.playbook.yml -s

I would like the output to be in JSON format, preferably combining the facts and the output of the list_vms.

How can I create a similar layout (one JSON per host in the out directory?) with the combined information?

2 Answers
Related