I'm trying to replace some variables in a dictionary according to the value in another dictionary, it works just fine on exact matches but it's enough to match only on the first few words.
- debug:
msg: "{{OS_short}}"
loop: "{{store_os}}"
vars:
_dict: "{{ OS|dict2items }}"
query: "[?contains(value, '{{ item.os_full }}')].key"
OS_short: "{{ _dict|json_query(query) | join ('\n')}}"
when: item.inventory.os_full is defined
Dictionary to match:
OS:
ios:
- IOS
- ios
nxos:
- NX-OS
- nx-os
- Cisco NX-OS(tm)
#- Cisco NX-OS(tm) nxos.bla bla bla
I've tried to use both "contains" and "starts_with" but with starts_with I'm getting "expected one of: ['string'], received: \"array\""}"
Using contains I'm only getting an empty answer
ok: [localhost] => (item={'os_full': 'Cisco NX-OS(tm) nxos.x.x.x.x.bin, Software (nxos), Version x.y(z), RELEASE SOFTWARE Copyright (c) 2002-2019 by Cisco Systems, Inc. Compiled 3/5/2019 12:00:00'}) => {
"msg": ""
}