Extract firmware version from idrac_firmware_info model

Hello,

I have the following code to get the firmware of the idrac.

---
- name: Get Installed Firmware Inventory
  dellemc.openmanage.idrac_firmware_info:
    idrac_ip: "{{ idrac_ip_host }}"
    idrac_user: "{{ idrac_user }}"
    idrac_password: "{{ idrac_password }}"
    validate_certs: False
  register: firmware_info

  tags: firmware   
- name: Display Firmware Information
  debug:
    msg: "Firmware Version: {{ firmware_info}}"
  tags: firmware 

This code showing all information about the firmware but I want to get only the firmware version example 4.10.10.0 wich is VersionString in the json output

this is an extract of my current output . The full output is longer than this and contains others values with VersionString)

      {
                  
                    "MajorVersion": "4",
                    "MinorVersion": "10",
                    "RevisionNumber": "10",
                    "RevisionString": null,
                    "Status": "Installed",
                    "SubDeviceID": null,
                    "SubVendorID": null,
                    "Updateable": "false",
                    "VendorID": null,
                    "VersionString": "4.10.10.10",
                    "impactsTPMmeasurements": "false"
                },

I will be glad to any help!
Thank you

Try this?

- name: Set a fact for the firmware_info
  ansible.builtin.set_fact:
    firmware_info_json: "{{ firmware_info | ansible.builtin.from_json }}"
  tags: firmware 

- name: Display Firmware Information
  debug:
    var: firmware_info_json.VersionString
  tags: firmware 

Hello,
This is the output result :
“msg”: “Unexpected templating type error occurred on ({{ firmware_info | ansible.builtin.from_json }}): the JSON object must be str, bytes or bytearray, not dict. the JSON object must be str, bytes or bytearray, not dict”}

I changed it after that by this

- name: Set a fact for the firmware_info
  ansible.builtin.set_fact:
    firmware_info_json: "{{ firmware_info }}"
  tags: firmware 

- name: Display Firmware Information
  debug:
    var: firmware_info_json.VersionString
  tags: firmware

it is not printing the value the result is :“firmware_info_json.VersionString”: “VARIABLE IS NOT DEFINED!”

Perhaps there is another element involved, VersionString might be a child of another element? What does the following result in?

- name: Display Firmware Information
  debug:
    var: firmware_info_json
  tags: firmware

this is will show all the json output. Yes it contain another StringVersion elements for cards and other elements.

Given the whole output I’m sure someone could suggest a method to extract the value you want, without the full output I would expect you might need to wait someone to also have the same hardware as you?

This is another extract with multiple elements: I don’t know if this could help

{
    "BuildNumber": "0",
    "Classifications": "10",
    "ComponentID": "",
    "ComponentType": "FRMW",
    "DeviceID": null,
    "ElementName": "Backplane 2",
    "FQDD": "",
    "HashValue": "",
    "IdentityInfoType": "",
    "IdentityInfoValue": "",
    "InstallationDate": "",
    "InstanceID": "",
    "IsEntity": "true",
    "Key": "",
    "MajorVersion": "4",
    "MinorVersion": "35",
    "RevisionNumber": "0",
    "RevisionString": null,
    "Status": "Installed",
    "SubDeviceID": null,
    "SubVendorID": null,
    "Updateable": "true",
    "VendorID": null,
    "VersionString": "4.35",
    "impactsTPMmeasurements": "false"
},
{
    "BuildNumber": "10",
    "Classifications": "10",
    "ComponentID": "",
    "ComponentType": "APAC",
    "DeviceID": null,
    "ElementName": "Lifecycle Controller",
    "FQDD": "",
    "HashValue": "",
    "IdentityInfoType": "",
    "IdentityInfoValue": "",
    "InstallationDate": "",
    "InstanceID": "",
    "IsEntity": "true",
    "Key": "",
    "MajorVersion": "4",
    "MinorVersion": "10",
    "RevisionNumber": "10",
    "RevisionString": null,
    "Status": "Installed",
    "SubDeviceID": null,
    "SubVendorID": null,
    "Updateable": "false",
    "VendorID": null,
    "VersionString": "4.10.10.10",
    "impactsTPMmeasurements": "false"
},
{
    "BuildNumber": null,
    "Classifications": "10",
    "ComponentID": "",
    "ComponentType": "APAC",
    "DeviceID": null,
    "ElementName": "Dell 64 Bit uEFI Diagnostics, version 4301, 4301A42, 4301.43",
    "FQDD": "",
    "HashValue": "",
    "IdentityInfoType": "",
    "IdentityInfoValue": "",
    "InstallationDate": "",
    "InstanceID": "",
    "IsEntity": "true",
    "Key": "",
    "MajorVersion": null,
    "MinorVersion": null,
    "RevisionNumber": null,
    "RevisionString": null,
    "Status": "Installed",
    "SubDeviceID": null,
    "SubVendorID": null,
    "Updateable": "true",
    "VendorID": null,
    "VersionString": "4301A42",
    "impactsTPMmeasurements": "false"
}

Do you know which ComponentType or ElementName or other thing you need to get the VersionString for?

And can you post the full output — the extract is not valid JSON so can’t be processed without editing to turn it into valid JSON…

1 Like

Thank you for your answer. I find the solution and gives me the result that I want. this is the solution

- name: Set a fact for the firmware_info
  ansible.builtin.set_fact:
    version: "{{ firmware_info | json_query('firmware_info.Firmware[*].VersionString') }}"
  tags: firmware

the firmware_info and Firmware is the beginning of my Json output.

1 Like

The information @chris was asking about, and which you removed from your posts, was the structure of the returned data “above” our “outside” the inner dicts.

The module docs include a sample which shows that firmware_info is a dict containing Firmware, which is itself a list if dicts which contain (among other things) VersionString. The canonical way to access that without using json_query() would be

{{ firmware_info.Firmware | map(attribute="VersionString") }}

Both methods return a list with as many elements as in the firmware_info.Firmware list.

2 Likes

Yes, Chris he was right without the first output he cannot help me. I removed the must important information from it. The problem is resolved by adding firmware_info | json_query(‘firmware_info.Firmware[*].VersionString’) to get the list of all VersionString.

That’s fine, but to use json_query one must first “install the jmespath dependency on the Ansible controller”*. Not everyone has that option, so I was showing how to do the equivalent with Ansible’s “out-of-the-box” tools.

2 Likes

Thanky ou very much @utoddl and @chris :blush:

2 Likes