I am looking to do some meta analysis of the execution of a playbook by setting stdout_callback = json
in ansible.cfg
and analysing the output.
Specifically I’d like to extract a list of tasks and whether for each host the task changed anything. AFAIK that should be expressed by the value of changed
under the host and task. I was hoping to use Ansible + json_query i.e. a jmespath filter to extract this information.
I see that the output looks like that below:
{
"plays": [
{
"play": {
"name": "Play 1"
},
"tasks": [
{
"hosts": {
"host1": {
"changed": true
},
"host2": {
"changed": false
}
},
"task": {
"name": "Task 1"
}
}
]
}
]
}
My desired extraction:
[
{
"task": "Task 1",
"hosts": [
"host1"
]
}
]
I’ve got as far as plays[].tasks[].{task: task.name, hosts: keys(hosts) | [?hosts[?@] ==
true]}
but that doesn’t work (as tested in https://play.jmespath.org/). I’m not sure how to filter the hosts based on the value of changed
and display the host name. Any help would be appreciated.