Use variable with item in when condition in ansible task

I’m using the below playbook to capture the vmware datacenter information, which is working fine without any issues:

what are you trying to do exactly?
i.e. what do you expect the debug task to show?

without knowing the structure of the datacenter variable, it’s not really possible to help

Your output tells you everything you need to know.

skipping: [localhost] => (item={‘name’: ‘Datacenter-Test’, ‘moid’: ‘datacenter-1247’, ‘config_status’: ‘gray’, ‘overall_status’: ‘gray’})
skipping: [localhost] => (item={‘name’: ‘opendc-rookie’, ‘moid’: ‘datacenter-2’, ‘config_status’: ‘gray’, ‘overall_status’: ‘gray’})
skipping: [localhost]

Your condition is

when:

In all of the data processed by the look, the value of ‘name’ is never ‘datacenter’ so the task is skipped.