json_query and set_fact prints only last value of the list

Hi,

The below values are looped with json_query and set_fact as you can see the entry BIOS contains three times when printing output it shows last BIOS value output.I may require the output of first BIOS value.

Could someone help here?

Here is the playbook

  • name: Get default system, user and firmware information
    redfish_info:
    category: Update
    baseuri: “{{ inventory_hostname }}”
    username: “”
    password: “”
    register: drac

  • set_fact:
    test: “{{ drac | json_query(my_query) }}”
    vars:
    my_query: “redfish_facts.firmware.entries.{Name : Name, Version: Version}”

  • debug: msg=“{{ drac }}”

  • set_fact:
    Firmware: “{{phonebook|default({}) | combine ( {item.Name : item.Version}) }}”
    with_items: “{{ test | json_query(‘[*]’)}}”

  • name: Firmware Vaule
    debug: var=Firmware

u’19.0.12’, u’Name’: u’Intel(R) Ethernet Converged Network Adapter X710 - F8:F2:1E:1F:3E:E0’})
u’19.0.12’, u’Name’: u’Intel(R) Ethernet Converged Network Adapter X710 - F8:F2:1E:1F:3E:E2’})
u’19.0.12’, u’Name’: u’Intel(R) Gigabit 4P X710/I350 rNDC - 24:6E:96:D1:77:58’})
u’2.46’, u’Name’: u’BP14G+EXP 0:1’})
u’15.00.00’, u’Name’: u’QLogic QLE2692 16Gb FC Adapter - 21000024FF1EFD60’})
u’50.9.3-2949’, u’Name’: u’PERC H740P Adapter’})
u’2.4.8’, u’Name’: u’BIOS’})
u’3.0’, u’Name’: u’OS COLLECTOR, 3.0, A00’})
u’19.0.12’, u’Name’: u’Intel(R) Ethernet Converged Network Adapter X710 - F8:F2:1E:1F:3E:E0’})
u’19.0.12’, u’Name’: u’Intel(R) Ethernet Converged Network Adapter X710 - F8:F2:1E:1F:3E:E2’})
u’19.0.12’, u’Name’: u’Intel(R) Gigabit 4P X710/I350 rNDC - 24:6E:96:D1:77:58’})
u’2.46’, u’Name’: u’BP14G+EXP 0:1’})
u’15.00.00’, u’Name’: u’QLogic QLE2692 16Gb FC Adapter - 21000024FF1EFD60’})
u’3.1.0’, u’Name’: u’iDRAC Service Module Installer 3.1.0, A00’})
u’00.23.32’, u’Name’: u’Power Supply.Slot.1’})
u’50.9.3-2949’, u’Name’: u’PERC H740P Adapter’})
u’DL5C’, u’Name’: u’Disk 0 in Backplane 1 of RAID Controller in Slot 6’})
u’DL5C’, u’Name’: u’Disk 2 in Backplane 1 of RAID Controller in Slot 6’})
u’2.4.8’, u’Name’: u’BIOS’})
u’17.08.12’, u’Name’: u’Dell OS Driver Pack, 17.08.12, A00’})
u’4.00.00.00’, u’Name’: u’Integrated Dell Remote Access Controller’})
u’4301A13’, u’Name’: u’Dell 32 Bit uEFI Diagnostics, version 4301, 4301A13, 4301.14’})
u’1.0.1’, u’Name’: u’System CPLD’})
u’4.00.00.00’, u’Name’: u’Lifecycle Controller’})
u’2.17’, u’Name’: u’BP14G+EXP 0:1’})
u’50.3.0-1022’, u’Name’: u’PERC H740P Adapter’})
u’1.4.8’, u’Name’: u’19.0.12’, u’Name’: u’Intel(R) Ethernet Converged Network Adapter X710 - F8:F2:1E:1F:3E:E0’})
u’19.0.12’, u’Name’: u’Intel(R) Ethernet Converged Network Adapter X710 - F8:F2:1E:1F:3E:E2’})
u’19.0.12’, u’Name’: u’Intel(R) Gigabit 4P X710/I350 rNDC - 24:6E:96:D1:77:58’})
u’2.46’, u’Name’: u’BP14G+EXP 0:1’})
u’15.00.00’, u’Name’: u’QLogic QLE2692 16Gb FC Adapter - 21000024FF1EFD60’})
u’50.9.3-2949’, u’Name’: u’PERC H740P Adapter’})
u’2.4.8’, u’Name’: u’BIOS’})
u’3.0’, u’Name’: u’OS COLLECTOR, 3.0, A00’})
u’19.0.12’, u’Name’: u’Intel(R) Ethernet Converged Network Adapter X710 - F8:F2:1E:1F:3E:E0’})
u’19.0.12’, u’Name’: u’Intel(R) Ethernet Converged Network Adapter X710 - F8:F2:1E:1F:3E:E2’})
u’19.0.12’, u’Name’: u’Intel(R) Gigabit 4P X710/I350 rNDC - 24:6E:96:D1:77:58’})
u’2.46’, u’Name’: u’BP14G+EXP 0:1’})
u’15.00.00’, u’Name’: u’QLogic QLE2692 16Gb FC Adapter - 21000024FF1EFD60’})
u’3.1.0’, u’Name’: u’iDRAC Service Module Installer 3.1.0, A00’})
u’00.23.32’, u’Name’: u’Power Supply.Slot.1’})
u’50.9.3-2949’, u’Name’: u’PERC H740P Adapter’})
u’DL5C’, u’Name’: u’Disk 0 in Backplane 1 of RAID Controller in Slot 6’})
u’DL5C’, u’Name’: u’Disk 2 in Backplane 1 of RAID Controller in Slot 6’})
u’2.4.8’, u’Name’: u’BIOS’})
u’17.08.12’, u’Name’: u’Dell OS Driver Pack, 17.08.12, A00’})
u’4.00.00.00’, u’Name’: u’Integrated Dell Remote Access Controller’})
u’4301A13’, u’Name’: u’Dell 32 Bit uEFI Diagnostics, version 4301, 4301A13, 4301.14’})
u’1.0.1’, u’Name’: u’System CPLD’})
u’4.00.00.00’, u’Name’: u’Lifecycle Controller’})
u’2.17’, u’Name’: u’BP14G+EXP 0:1’})
u’50.3.0-1022’, u’Name’: u’PERC H740P Adapter’})
u’1.4.8’, u’Name’: u’BIOS’})
u’3.15.17.15’, u’Name’: u’Integrated Dell Remote Access Controller’})‘})
u’3.15.17.15’, u’Name’: u’Integrated Dell Remote Access Controller’})

Regards
Kumar

Hello,

You can use the "first" jinja filter to only return the first result of the list
https://jinja.palletsprojects.com/en/2.11.x/templates/#first

Good luck!