gcp_compute_instance_info >> filters

34 views
Skip to first unread message

Yantram Cloud

unread,
Sep 21, 2020, 9:08:00 AM9/21/20
to Ansible Project
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
register: instances

Dick Visser

unread,
Sep 21, 2020, 10:56:37 AM9/21/20
to ansible...@googlegroups.com
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.

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/904af85e-17bb-4975-92a7-ad60eeac9c68n%40googlegroups.com.


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Yantram Cloud

unread,
Sep 21, 2020, 11:05:47 AM9/21/20
to ansible...@googlegroups.com
My Bad, DId not realize the formatting got messed up.
Here is the right format.

- 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
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

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/2Y5orHeAH40/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwNmpb8D28Fdvn5i2a%2BL7ZmVByg5pYgyUVvi_-7VW3EpRQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages