I have a shell script which executes an ansible playbook and I want to process the output of this playbook. I am not sure how can I do this.
Script:
#!/bin/sh
ansible-playbook -i inventory/ec2.py services_status.yml
The output of ansible-playbook command is:
PLAY [all] *********************************************************************
TASK [cmx_running_services] ****************************************************
ok: [172.31.35.225]
ok: [172.31.9.253]
TASK [debug] *******************************************************************
ok: [172.31.35.225] => {
"services": {
"changed": false,
"meta": {
"services": [
"zk",
"kafka"
]
}
}
}
ok: [172.31.9.253] => {
"services": {
"changed": false,
"meta": {
"MyService": [
"default"
],
"services": [
"monitoring-agent"
]
}
}
}
PLAY RECAP *********************************************************************
172.31.35.225 : ok=2 changed=0 unreachable=0 failed=0
172.31.9.253 : ok=2 changed=0 unreachable=0 failed=0
In my script I want to process this output and store a json object in format:
{
"172.31.35.225":{
"services":[
"zk",
"kafka"
]
},
"172.31.9.253":{
"MyService":[
"default"
],
"services":[
"monitoring-agent"
]
}
}