# gcp\_compute\_instance\_info \>\> filters

**URL:** <https://forum.ansible.com/t/gcp-compute-instance-info-filters/33859>\
**Category:** Ansible Project\
**Created:** [September 21, 2020, 1:07pm UTC](https://forum.ansible.com/t/gcp-compute-instance-info-filters/33859 "2020-09-21T13:07:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yantram\_Cloud](https://avatars.discourse-cdn.com/v4/letter/y/c0e974/32.png) [@Yantram\_Cloud](https://forum.ansible.com/u/Yantram_Cloud)\
**Post date:** [September 21, 2020, 1:07pm UTC](https://forum.ansible.com/t/gcp-compute-instance-info-filters/33859/1 "2020-09-21T13:07:59Z")

</div>

I am trying to implemet filtering based on the tags which my vm has.  
unfortunately have not been able to get it to work. Can someone share an example here.

here is my current playbook.

- name: Locate Instance  
hosts: localhost  
gather\_facts: false  
tasks:
- name: search for google instances  
gcp\_compute\_instance\_info:  
filters:
- name = webserver
- tags = webserver

# - name = test\_object

zone: us-central1-a  
project: concise-rampart-288609  
auth\_kind: serviceaccount  
service\_account\_file: ~/Downloads/concise-rampart-288609-3d94f060ecb5.json  
scopes:

- [https://www.googleapis.com/auth/compute](https://www.googleapis.com/auth/compute)  
register: instances

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 21, 2020, 2:56pm UTC](https://forum.ansible.com/t/gcp-compute-instance-info-filters/33859/2 "2020-09-21T14:56:05Z")

</div>

I don’t have an answer, but could you please make sure your playbook code is properly indented?  
This appears to be the sources of many errors lately.

---

<div class="post-metadata">

**Author:** ![Yantram\_Cloud](https://avatars.discourse-cdn.com/v4/letter/y/c0e974/32.png) [@Yantram\_Cloud](https://forum.ansible.com/u/Yantram_Cloud)\
**Post date:** [September 21, 2020, 3:04pm UTC](https://forum.ansible.com/t/gcp-compute-instance-info-filters/33859/3 "2020-09-21T15:04:40Z")

</div>

My Bad, DId not realize the formatting got messed up.  
Here is the right format.

```auto
- name: Locate Instance
  hosts: localhost
  gather_facts: false
  tasks:
   - name: search for google instances
     gcp_compute_instance_info:
       filters:
# - tags.items = [webserver]
       - name = webserver
       zone: us-central1-a
       project: {{ gcp_project }}
       auth_kind: serviceaccount
       service_account_file: {{ service_account }}
       scopes:
         - [https://www.googleapis.com/auth/compute](https://www.googleapis.com/auth/compute)
     register: instances

   - name: Add all the retrieved instances ip_address to a dynamic inventory
     add_host: hostname={{ item.networkInterfaces[0].accessConfigs[0].natIP }} groupname=new_instances
     with_items: "{{ instances.resources }}"

     # - "{{ disk['resources']['name'] }}"
     # - "{{ ansible_facts }}"
     # - "{{ gcp_compute_disk_name | select('match', '^(gcp-compute-disk)') | list }}"
     when: instances is defined

```
