I would probably solve this with a few lines of python for convenience and easier maintenance. Example below is with a custom filter plugin adjacent to playbook but you can distribute this as part of a collection
In the below example, I'll pass a list of keys which can appear anywhere in you original dict and need to be down-cased. This gives you control over the exact data to lower case and you can pass several keys if needed.
This is the example file structure:
.
├── filter_plugins
│ └── my_facts_filters.py
└── playbook.yml
This is the filter_plugins/my_facts_filters.py
custom filter (adapted from an other answer):
from ansible.errors import AnsibleError
def inspect_and_replace(data, elements_list):
if isinstance(data, (dict, list)):
for k, v in (data.items() if isinstance(data, dict) else enumerate(data)):
if k in elements_list and isinstance(v, str):
data[k] = v.lower()
inspect_and_replace(v, elements_list)
def elements_to_lower(input_dict, elements_list):
# Raise an ansible error in input is not a dict
try:
assert isinstance(input_dict, dict)
except AssertionError:
raise AnsibleError(f'Input is not a dict. Got {type(input_dict)}')
try:
assert isinstance(elements_list, list)
except AssertionError:
raise AnsibleError(f'filter argument (i.e. elements to downcase) is not a list. Got {type(elements_list)}')
inspect_and_replace(input_dict, elements_list)
return input_dict
class FilterModule(object):
"""my facts filters."""
def filters(self):
"""Return the filter list."""
return {
'elements_to_lower': elements_to_lower
}
A minimal test playbook:
---
- hosts: localhost
gather_facts: false
tasks:
- name: Dummy task to set the same var (I believe...) as in your example
ansible.builtin.set_fact:
facts:
instance:
config:
hardware:
device:
- backing:
uuid: 5A2c32a-f1G85g-2035-0483-1fe9c129216d
unitNumber: 0
- name: Use custom filter to transform needed elements
ansible.builtin.debug:
msg: "{{ facts | elements_to_lower(['uuid']) }}"
results in:
$ ansible-playbook playbook.yml
PLAY [localhost] **************************************************************************************************************************************************************************************************************
TASK [Dummy task to set the same var (I believe...) as in your example] *******************************************************************************************************************************************************
ok: [localhost]
TASK [Use custom filter to transform needed elements] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": {
"instance": {
"config": {
"hardware": {
"device": [
{
"backing": {
"uuid": "5a2c32a-f1g85g-2035-0483-1fe9c129216d"
},
"unitNumber": 0
}
]
}
}
}
}
}
PLAY RECAP ********************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0