<p>Thanks for your response @Zeitounator. I'm running Ansible 2.8
Since posting this I have received an answer that works for me. I realized that these facts are presented as a list of dicts as noted in the <a href="https://docs.ansible.com/ansible/2.8/modules/vmware_vm_facts_module.html" rel="nofollow noreferrer">doco</a>, but I was still having trouble for some reason (confused myself badly.) The solution hinges on using with_items instead of with_dict and using an appropriate conditional like so:</p>

<pre><code>  - name: Test vmware_vm_facts
    vmware_vm_facts:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      validate_certs: no
    delegate_to: localhost
    register: rc


  - debug:
      msg: "IP of {{ item.guest_name }} ({{ item.uuid }}) is {{ item.ip_address }} and power is {{ item.power_state }}"
    with_items: "{{ rc.virtual_machines }}"
    when: item.guest_name is search(inventory_hostname)
</code></pre>

CC BY-SA 4.0
2020-01-23T13:39:16.853Z
2020-01-23T13:39:16.853Z
richf
<p>I'm trying to pull out the "uuid" from facts returned by ansible's vmware_vm_facts module. There is a solution to a similar question <a href="https://www.reddit.com/r/ansible/comments/6wfu4d/filter_vmware_vm_facts/" rel="nofollow noreferrer">posted on Reddit</a>, but when I try that, it fails with 
'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'ip_address'</p>

<p>Here is my code:</p>

<pre><code>  - name: Test vmware_vm_facts
    vmware_vm_facts:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      validate_certs: no
    delegate_to: localhost
    register: rc

  - name: Debug...
    debug:
      msg: "IP of {{ item.key }} is {{ item.value.ip_address }}and power is {{ item.value.power_state }}"
    with_dict: "{{ rc.virtual_machines }}"
</code></pre>

<p>Anyone have any ideas?
Thanks!</p>

CC BY-SA 4.0
2020-01-21T22:54:53.467Z
Which ansible version are your running ? Can you please show a debug of your full `item` ?
Zeitounator
CC BY-SA 4.0
2020-01-23T13:24:39.580Z
I'm running Ansible 2.8Since posting this I have received an answer that works for me. I was
richf
<ansible><vmware>
How to filter vmware_vm_facts
richf
# How to filter vmware_vm_facts

(Asked by: username_0 on 2020-01-20)

I'm trying to pull out the "uuid" from facts returned by ansible's vmware_vm_facts module. There is a solution to a similar question posted on Reddit, but when I try that, it fails with 
'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'ip_address'
Here is my code:
  - name: Test vmware_vm_facts
    vmware_vm_facts:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      validate_certs: no
    delegate_to: localhost
    register: rc

  - name: Debug...
    debug:
      msg: "IP of {{ item.key }} is {{ item.value.ip_address }}and power is {{ item.value.power_state }}"
    with_dict: "{{ rc.virtual_machines }}"

Anyone have any ideas?
Thanks!

**Tags:** ansible, vmware

> **Comments:**
> **username_1**: Which ansible version are your running ? Can you please show a debug of your full `item` ?  
> **username_0**: I'm running Ansible 2.8Since posting this I have received an answer that works for me. I was  

---

## 1 answers

### Answer by username_0 on 2020-01-23. Score: 1

Thanks for your response @username_1. I'm running Ansible 2.8
Since posting this I have received an answer that works for me. I realized that these facts are presented as a list of dicts as noted in the doco, but I was still having trouble for some reason (confused myself badly.) The solution hinges on using with_items instead of with_dict and using an appropriate conditional like so:
  - name: Test vmware_vm_facts
    vmware_vm_facts:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      validate_certs: no
    delegate_to: localhost
    register: rc


  - debug:
      msg: "IP of {{ item.guest_name }} ({{ item.uuid }}) is {{ item.ip_address }} and power is {{ item.power_state }}"
    with_items: "{{ rc.virtual_machines }}"
    when: item.guest_name is search(inventory_hostname)


---

