long time listener / first time caller.
In ansible, I’m using the json_query in jmespath and am unable to figure out how to make it do what i want exactly. If I have a blob of data like this about a collection of hosts stored in memory from an earlier command.
{"count":1,"hostname":"machine1.my_fqdn.com","motherBoard":{"uniqueID":"EWTD43JD”},”System":{"makerID":"AAAA"},"bios":{"vers”:”4.10"},"bmc":{"firmware_vers”:”4.12"}},
{"count":1,"hostname":"machine2.my_fqdn.com","motherBoard":{"uniqueID”:”EHFG47G4”},”System":{"makerID":"AAAA"},"bios":{"vers”:”4.5”},”bmc":{"firmware_vers”:”4.07"}},
{"count":1,"hostname":"machine3.my_fqdn.com","motherBoard":{"uniqueID”:”2HEF7JE4”},”System":{"makerID":"AAAA"},"bios":{"vers”:”4.9”},”bmc":{"firmware_vers”:”4.11"}},
{"count":1,"hostname":"machine4.my_fqdn.com","motherBoard":{"uniqueID”:”3GEDHJD4”},”System":{"makerID":"AAAA"},"bios":{"vers”:”4.10"},"bmc":{"firmware_vers”:”4.12"}},
{"count":1,"hostname":"machine5.my_fqdn.com","motherBoard":{"uniqueID”:”QYE7DJD3”},”System":{"makerID":"AAAA"},"bios":{"vers”:”4.10"},"bmc":{"firmware_vers”:”4.12"}},
{"count":1,"hostname":"machine6.my_fqdn.com","motherBoard":{"uniqueID”:”HYH5TRHD”},”System":{"makerID”:”BBBB”},”bios":{"vers”:”4.5”},”bmc":{"firmware_vers”:”4.07"}},
{"count":1,"hostname":"machine7.my_fqdn.com","motherBoard":{"uniqueID”:”QW3EDG4Z”},”System":{"makerID”:”BBBB”},”bios":{"vers”:”4.5”},”bmc":{"firmware_vers”:”4.07"}},
{"count":1,"hostname":"machine8.my_fqdn.com","motherBoard":{"uniqueID”:”A12HRUKF”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine9.my_fqdn.com","motherBoard":{"uniqueID”:”HERK5H90”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine10.my_fqdn.com","motherBoard":{"uniqueID”:”1HEHGYPM”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine11.my_fqdn.com","motherBoard":{"uniqueID":"AHYG67V9”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine12.my_fqdn.com","motherBoard":{"uniqueID”:”TRDG5JD1”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine13.my_fqdn.com","motherBoard":{"uniqueID”:”WHEJ7UH4”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine14.my_fqdn.com","motherBoard":{"uniqueID”:”OIU7UJ67”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine15.my_fqdn.com","motherBoard":{"uniqueID”:”UI76YTH6”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine16.my_fqdn.com","motherBoard":{"uniqueID”:”1QE347T3”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine17.my_fqdn.com","motherBoard":{"uniqueID”:”I89IO06Y”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine18.my_fqdn.com","motherBoard":{"uniqueID”:”ETDG5TGR”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine19.my_fqdn.com","motherBoard":{"uniqueID”:”23FHGHEK”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine20.my_fqdn.com","motherBoard":{"uniqueID”:”34DEGHEJ”},”System":{"makerID":"CCCC"},"bios":{"vers”:”8.17"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine21.my_fqdn.com","motherBoard":{"uniqueID”:”23GREHGN”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine22.my_fqdn.com","motherBoard":{"uniqueID”:”4FZADFXS”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine23.my_fqdn.com","motherBoard":{"uniqueID”:”QYDUJY76”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
{"count":1,"hostname":"machine24.my_fqdn.com","motherBoard":{"uniqueID”:”RHEHDJ45”},”System":{"makerID":"CCCC"},"bios":{"vers":"8.15"},"bmc":{"firmware_vers":"8.25"}},
My playbook contains:
- name: figure out the bios versions
ansible.builtin.debug:
msg:
- "{{ earlierComand_output.stdout | from_json | json_query ('[*].{ uniqueID: System. makerID, version: bios.vers}') | list | unique}}"
that gives me:
TASK [figure out the bios versions] ****************************************************************************************************************
ok: [localhost] =>{
"msg":[
[
{
"makerID": “AAAA”,
"version": “4.10"
},
{
"makerID": “AAAA”,
"version": “4.5”
},
{
"makerID": “AAAA”,
"version": “4.9”
},
{
"makerID": “BBBB”,
"version": “4.5”
},
{
"makerID": “CCCC”,
"version": “8.15"
},
{
"makerID": “CCCC”,
"version": “8.17"
}
]
]
}
but what I want is to not only list these, but count them and print a clean result like:
“makerID”: “AAAA”, “version”: “4.10”, “quantity”: “3”
"makerID": “AAAA”, "version": “4.5”, “quantity”: “1”
"makerID": “AAAA”, "version": “4.9”, “quantity”: “1”
"makerID": “BBBB”, "version": “4.5”, “quantity”: “2”
"makerID": “CCCC”, "version": “8.15”, “quantity”: “16”
"makerID": “CCCC”, "version": “8.17”, “quantity: “1”
when I try to add a | length or any other command, it gives me the number 6, meaning there are only 6 results. Since the results are dynamic, I'm unclear how to parse data that I don't know and count it.