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 On Thu, 4 Aug 2022 at 08:41, 'Pugazhendhi Ramakrishnan' via Ansible Project <[email protected]> wrote: > I'm using the below playbook to capture the vmware datacenter information, > which is working fine without any issues: > > --- > - hosts: localhost > vars_files: 1credentials.yml > tasks: > - name: Gather information about all datacenters > community.vmware.vmware_datacenter_info: > hostname: '{{ vcenter_hostname }}' > username: '{{ vcenter_username }}' > password: '{{ vcenter_password }}' > validate_certs: no > delegate_to: localhost > register: datacenter > > - debug: > msg: "{{ item.name }}" > loop: "{{ datacenter.datacenter_info }}" > when: > - item.name is defined > - item.name == datacenter > > below is the output: > > PLAY [localhost] > ******************************************************************************************************************************************************* > > TASK [Gathering Facts] > ************************************************************************************************************************************************* > ok: [localhost] > > TASK [Gather information about all datacenters] > ************************************************************************************************************************ > ok: [localhost] > > TASK [debug] > *********************************************************************************************************************************************************** > skipping: [localhost] => (item={'name': 'Datacenter-Test', 'moid': > 'datacenter-1247', 'config_status': 'gray', 'overall_status': 'gray'}) > ok: [localhost] => (item={'name': 'opendc-rookie', 'moid': 'datacenter-2', > 'config_status': 'gray', 'overall_status': 'gray'}) => { > "msg": "opendc-rookie" > } > > PLAY RECAP > ************************************************************************************************************************************************************* > localhost : ok=3 changed=0 unreachable=0 > failed=0 skipped=0 > > > But when I try to use a variable for the datacenter value as below: > > --- > - hosts: localhost > vars_files: 1credentials.yml > vars: > datacenter: opendc-rookie > tasks: > - name: Gather information about all datacenters > community.vmware.vmware_datacenter_info: > hostname: '{{ vcenter_hostname }}' > username: '{{ vcenter_username }}' > password: '{{ vcenter_password }}' > validate_certs: no > delegate_to: localhost > register: datacenter > > - debug: > msg: "{{ item.name }}" > loop: "{{ datacenter.datacenter_info }}" > when: > - item.name is defined > - item.name == "datacenter" > > It is skipping the debug task. Kindly suggest how can I incorporate the > variable value with the when condition having item. Below is the output > skipping the variable > PLAY [localhost] > ******************************************************************************************************************************************************* > > TASK [Gathering Facts] > ************************************************************************************************************************************************* > ok: [localhost] > > TASK [Gather information about all datacenters] > ************************************************************************************************************************ > ok: [localhost] > > TASK [debug] > *********************************************************************************************************************************************************** > 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] > > PLAY RECAP > ************************************************************************************************************************************************************* > localhost : ok=2 changed=0 unreachable=0 > failed=0 skipped=1 rescued=0 ignored=0 > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/90c18c21-04f1-4313-932d-0eed6b27c54cn%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/90c18c21-04f1-4313-932d-0eed6b27c54cn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLaVcyUeyRpB4Ls1ZbWdUdzfKj8MiW5TseP83LNBkrsSgw%40mail.gmail.com.
