How to parse variable variable to use json path

Hello,

i am currently working on vm provisioning using ansible and i need to know the available disk size of my datastore before using the vmware_guest module to create my vm.
When I try to retrieve my variable using json path I get the following message.
Could you please help me ?

==========
Declaration de ma variable:

set_fact:
datastorefree: “{{ item.ansible_facts.ansible_datastore[?(@.name == ‘MED_G1500_821_NR14’)].free }}”
loop: “{{ host_facts.results }}”

quand je lance, ansible n’aime pas le “?”

TASK [create_vm : Get Free available for datastore collected] *********************************************************************
fatal: [localhost]: FAILED! => {“msg”: “template error while templating string: unexpected char u’?’ at 40. String: {{ item.ansible_facts.ansible_datastore[?(@.name == ‘MED_G1500_821_NR14’)].free }}”}

Hello babagadji

try this instead:

{{ item.ansible_facts.ansible_datastore["?(@.name == ‘MED_G1500_821_NR14’")].free }}

Thanks,
KodeKloud Support