# Extract firmware version from idrac\_firmware\_info model

**URL:** <https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935>\
**Category:** Get Help\
**Tags:** dellemc\
**Created:** [November 15, 2024, 3:48pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935 "2024-11-15T15:48:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![kou](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@kou](https://forum.ansible.com/u/kou)\
**Post date:** [November 15, 2024, 3:48pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/1 "2024-11-15T15:48:02Z")

</div>

Hello,

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

```auto
---
- 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)

```auto
      {
                  
                    "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

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [November 15, 2024, 4:39pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/2 "2024-11-15T16:39:36Z")

</div>

Try this?

```yaml
- 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 

```

---

<div class="post-metadata">

**Author:** ![kou](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@kou](https://forum.ansible.com/u/kou)\
**Post date:** [November 18, 2024, 6:59am UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/3 "2024-11-18T06:59:26Z")

</div>

> [@chris](#):
>
> ```auto
> - 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

```auto
- 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!”

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [November 18, 2024, 9:19am UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/4 "2024-11-18T09:19:13Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![kou](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@kou](https://forum.ansible.com/u/kou)\
**Post date:** [November 18, 2024, 10:42am UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/5 "2024-11-18T10:42:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [November 18, 2024, 10:44am UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/6 "2024-11-18T10:44:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kou](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@kou](https://forum.ansible.com/u/kou)\
**Post date:** [November 18, 2024, 10:54am UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/7 "2024-11-18T10:54:55Z")

</div>

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

```auto
{
    "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"
}

```

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [November 18, 2024, 11:34am UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/8 "2024-11-18T11:34:02Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![kou](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@kou](https://forum.ansible.com/u/kou)\
**Post date:** [November 18, 2024, 1:00pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/9 "2024-11-18T13:00:47Z")

</div>

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

```auto
- 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.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [November 18, 2024, 2:02pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/10 "2024-11-18T14:02:05Z")

</div>

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](https://docs.ansible.com/ansible/latest/collections/dellemc/openmanage/idrac_firmware_info_module.html#return-firmware_info) 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.

---

<div class="post-metadata">

**Author:** ![kou](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@kou](https://forum.ansible.com/u/kou)\
**Post date:** [November 18, 2024, 2:06pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/11 "2024-11-18T14:06:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [November 18, 2024, 2:15pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/12 "2024-11-18T14:15:04Z")

</div>

That’s fine, but to use `json_query` one must first “install the **jmespath** dependency on the Ansible controller”[\*](https://docs.ansible.com/ansible/latest/collections/community/general/docsite/filter_guide_selecting_json_data.html#selecting-json-data-json-queries). Not everyone has that option, so I was showing how to do the equivalent with Ansible’s “out-of-the-box” tools.

---

<div class="post-metadata">

**Author:** ![kou](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@kou](https://forum.ansible.com/u/kou)\
**Post date:** [November 18, 2024, 2:20pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/14 "2024-11-18T14:20:47Z")

</div>

Thanky ou very much @utoddl and @chris 😊

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 18, 2024, 2:21pm UTC](https://forum.ansible.com/t/extract-firmware-version-from-idrac-firmware-info-model/10935/15 "2024-12-18T14:21:20Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
