0

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.

KDP
  • 1
  • 2
  • perhaps I need to set the first result as var1, then the second as var2, etc... and then do a query and count those results. But the number of vars will be unknown, so that will be a challenge for me as well. – KDP Jan 26 '23 at 01:21
  • yes, first save to a variable then iterate over it via `selectattr` and `count` or something like that. – gildux Jan 26 '23 at 07:30

2 Answers2

0

I'm not sure that json_query is the right tool for this job. For example, you could write something like this:

- hosts: localhost
  gather_facts: false
  tasks:
    - set_fact:
        mvcount: >-
          {{ mvcount | combine({mvkey: mvcount.get(mvkey, 0) + item.count}) }}
      vars:
        mvcount: {}
        mvkey: "{{ item.System.makerID }}-{{ item.bios.vers }}"
      loop: "{{ earlierCommand_output.stdout | from_json }}"

    - debug:
        var: mvcount

I've made a couple of assumptions here, because your examples weren't entirely clear. For example, I'm assuming that earlierCommand_out.stdout actually contains a JSON list, like:

[
    {"count":1,"hostname":"machine1.my_fqdn.com", ...},
    {"count":1,"hostname":"machine2.my_fqdn.com", ...},
    etc.
]

If that assumption holds true, then running the above playbook with your sample data produces:

TASK [debug] ********************************************************************************************
ok: [localhost] => {
    "mvcount": {
        "AAAA-4.10": 3,
        "AAAA-4.5": 1,
        "AAAA-4.9": 1,
        "BBBB-4.5": 2,
        "CCCC-8.15": 16,
        "CCCC-8.17": 1
    }
}

That's exactly the information you're looking for, although formatted slightly differently. If you wanted to generate a report, you could pass that mvcount variable into a template. If we write:

- copy:
    dest: report.txt
    content: |
      {% for k, v in mvcount.items() %}
      {% set makerid = k.split('-')[0] %}
      {% set biosversion = k.split('-')[1] %}
      "makerID": "{{ makerid }}", "version": "{{ biosversion }}", "quantity": "{{ v }}"
      {% endfor %}

Then we get as output in report.txt:

"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"
larsks
  • 277,717
  • 41
  • 399
  • 399
0

Fix the data. Replace the malformatted double quotes

    data: "{{ earlierComand_output.stdout|regex_replace(stdout_regex, stdout_replace) }}"
    stdout_regex: '”'
    stdout_replace: '"'

There are many options:

  1. Use the filter community.general.counter. For example,
  makerID_quantity_str: |
      [{% for i in data|groupby('System.makerID') %}
      {% for k,v in (i.1|json_query('[].bios.vers')|community.general.counter).items() %}
      {makerID: {{ i.0 }}, version: {{ k }}, quantity: {{ v }}},
      {% endfor %}
      {% endfor %}]
  makerID_quantity: "{{ makerID_quantity_str|from_yaml }}"

Note: Instead of json_query you can map attribute

      {% for k,v in (i.1|map(attribute='bios.vers')|community.general.counter).items() %}

gives

  makerID_quantity:
    - {makerID: AAAA, quantity: 3, version: 4.1}
    - {makerID: AAAA, quantity: 1, version: 4.5}
    - {makerID: AAAA, quantity: 1, version: 4.9}
    - {makerID: BBBB, quantity: 2, version: 4.5}
    - {makerID: CCCC, quantity: 16, version: 8.15}
    - {makerID: CCCC, quantity: 1, version: 8.17}

  1. Use the filter length. Group data by System.makerID and get the list of makerID. Next, group the lists by bios.vers. In a Jinja template, iterate the lists and create the expected structure
  makerID_groups: "{{ data|groupby('System.makerID') }}"
  makerID_list: "{{ makerID_groups|map('first') }}"
  version_groups: "{{ makerID_groups|map('last')|map('groupby', 'bios.vers') }}"
  makerID_quantity_str: |
    [{% for id,versions in makerID_list|zip(version_groups) %}
    {% for ver in versions %}
    {makerID: {{ id }}, version: {{ ver.0 }}, quantity: {{ ver.1|length }}},
    {% endfor %}
    {% endfor %}]
  makerID_quantity: "{{ makerID_quantity_str|from_yaml }}"

gives the same list

  makerID_quantity:
    - {makerID: AAAA, quantity: 3, version: 4.1}
    - {makerID: AAAA, quantity: 1, version: 4.5}
    - {makerID: AAAA, quantity: 1, version: 4.9}
    - {makerID: BBBB, quantity: 2, version: 4.5}
    - {makerID: CCCC, quantity: 16, version: 8.15}
    - {makerID: CCCC, quantity: 1, version: 8.17}

Format the output. For example,

    - debug:
        msg: |
          {% for i in makerID_quantity %}
          "makerID": "{{ i.makerID }}", "version": "{{ i.version }}", "quantity": "{{ i.quantity }}"
          {% endfor %}

gives what you want

  msg: |-
    "makerID": "AAAA", "version": "4.1", "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"

Example of a complete playbook for testing

- hosts: localhost

  vars:

    earlierComand_output:
      stdout: |
        [
        {"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"}},
        ]

    data: "{{ earlierComand_output.stdout|regex_replace(stdout_regex, stdout_replace) }}"
    stdout_regex: '”'
    stdout_replace: '"'

    makerID_groups: "{{ data|groupby('System.makerID') }}"
    makerID_list: "{{ makerID_groups|map('first') }}"
    version_groups: "{{ makerID_groups|map('last')|map('groupby', 'bios.vers') }}"
    makerID_quantity_str: |
      [{% for id,versions in makerID_list|zip(version_groups) %}
      {% for ver in versions %}
      {makerID: {{ id }}, version: {{ ver.0 }}, quantity: {{ ver.1|length }}},
      {% endfor %}
      {% endfor %}]
    makerID_quantity: "{{ makerID_quantity_str|from_yaml }}"

  tasks:

    - debug:
        var: makerID_groups
    - debug:
        var: makerID_list
    - debug:
        var: version_groups
    - debug:
        var: makerID_quantity|to_yaml
    - debug:
        msg: |
          {% for i in makerID_quantity %}
          "makerID": "{{ i.makerID }}", "version": "{{ i.version }}", "quantity": "{{ i.quantity }}"
          {% endfor %}

gives

PLAY [localhost] ******************************************************************************************************************************************************************************

TASK [debug] **********************************************************************************************************************************************************************************
ok: [localhost] => 
  makerID_groups|to_yaml: |-
    - - AAAA
      - - System: {makerID: AAAA}
          bios: {vers: '4.10'}
          bmc: {firmware_vers: '4.12'}
          count: 1
          hostname: machine1.my_fqdn.com
          motherBoard: {uniqueID: EWTD43JD}
        - System: {makerID: AAAA}
          bios: {vers: '4.5'}
          bmc: {firmware_vers: '4.07'}
          count: 1
          hostname: machine2.my_fqdn.com
          motherBoard: {uniqueID: EHFG47G4}
        - System: {makerID: AAAA}
          bios: {vers: '4.9'}
          bmc: {firmware_vers: '4.11'}
          count: 1
          hostname: machine3.my_fqdn.com
          motherBoard: {uniqueID: 2HEF7JE4}
        - System: {makerID: AAAA}
          bios: {vers: '4.10'}
          bmc: {firmware_vers: '4.12'}
          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}
    - - BBBB
      - - System: {makerID: BBBB}
          bios: {vers: '4.5'}
          bmc: {firmware_vers: '4.07'}
          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}
    - - CCCC
      - - System: {makerID: CCCC}
          bios: {vers: '8.15'}
          bmc: {firmware_vers: '8.25'}
          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.17'}
          bmc: {firmware_vers: '8.25'}
          count: 1
          hostname: machine20.my_fqdn.com
          motherBoard: {uniqueID: 34DEGHEJ}
        - System: {makerID: CCCC}
          bios: {vers: '8.15'}
          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}

TASK [debug] **********************************************************************************************************************************************************************************
ok: [localhost] => 
  makerID_list:
  - AAAA
  - BBBB
  - CCCC

TASK [debug] **********************************************************************************************************************************************************************************
ok: [localhost] => 
  version_groups|to_yaml: |-
    - - - '4.10'
        - - System: {makerID: AAAA}
            bios: {vers: '4.10'}
            bmc: {firmware_vers: '4.12'}
            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: 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}
      - - '4.5'
        - - System: {makerID: AAAA}
            bios: {vers: '4.5'}
            bmc: {firmware_vers: '4.07'}
            count: 1
            hostname: machine2.my_fqdn.com
            motherBoard: {uniqueID: EHFG47G4}
      - - '4.9'
        - - System: {makerID: AAAA}
            bios: {vers: '4.9'}
            bmc: {firmware_vers: '4.11'}
            count: 1
            hostname: machine3.my_fqdn.com
            motherBoard: {uniqueID: 2HEF7JE4}
    - - - '4.5'
        - - System: {makerID: BBBB}
            bios: {vers: '4.5'}
            bmc: {firmware_vers: '4.07'}
            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}
    - - - '8.15'
        - - System: {makerID: CCCC}
            bios: {vers: '8.15'}
            bmc: {firmware_vers: '8.25'}
            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: 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}
      - - '8.17'
        - - System: {makerID: CCCC}
            bios: {vers: '8.17'}
            bmc: {firmware_vers: '8.25'}
            count: 1
            hostname: machine20.my_fqdn.com
            motherBoard: {uniqueID: 34DEGHEJ}

TASK [debug] **********************************************************************************************************************************************************************************
ok: [localhost] => 
  makerID_quantity|to_yaml: |-
    - {makerID: AAAA, quantity: 3, version: 4.1}
    - {makerID: AAAA, quantity: 1, version: 4.5}
    - {makerID: AAAA, quantity: 1, version: 4.9}
    - {makerID: BBBB, quantity: 2, version: 4.5}
    - {makerID: CCCC, quantity: 16, version: 8.15}
    - {makerID: CCCC, quantity: 1, version: 8.17}

TASK [debug] **********************************************************************************************************************************************************************************
ok: [localhost] => 
  msg: |-
    "makerID": "AAAA", "version": "4.1", "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"

PLAY RECAP ************************************************************************************************************************************************************************************
localhost: ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • these are great ideas and have worked to give me exactly what I need. Thank you so much all, I'm super excited to get over this stumbling block – KDP Jan 27 '23 at 00:47