Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-23T13:39:16.853Z
Answers: 2020-01-23T13:39:16.853Z
Answers: richf
Body: <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>
  
Comments: CC BY-SA 4.0
Comments: 2020-01-21T22:54:53.467Z
Comments: Which ansible version are your running ? Can you please show a debug of your full `item` ?
Comments: Zeitounator
Comments: CC BY-SA 4.0
Comments: 2020-01-23T13:24:39.580Z
Comments: I'm running Ansible 2.8Since posting this I have received an answer that works for me. I was
Comments: richf
Tags: <ansible><vmware>
Title: How to filter vmware_vm_facts
UserDisplayName: richf
ThreadText: # 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](https://www.reddit.com/r/ansible/comments/6wfu4d/filter_vmware_vm_facts/), 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](https://docs.ansible.com/ansible/2.8/modules/vmware_vm_facts_module.html), 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)
  
  ```
  
  
  ---
  
  