# GCP: How to pull inventory dynamically with multiple labels using Inventory Plugins?

**URL:** <https://forum.ansible.com/t/gcp-how-to-pull-inventory-dynamically-with-multiple-labels-using-inventory-plugins/32063>\
**Category:** Ansible Project\
**Tags:** azure, gcp, aws\
**Created:** [January 27, 2020, 11:30am UTC](https://forum.ansible.com/t/gcp-how-to-pull-inventory-dynamically-with-multiple-labels-using-inventory-plugins/32063 "2020-01-27T11:30:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sreenivas\_Chokkarapu](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sreenivas\_Chokkarapu](https://forum.ansible.com/u/Sreenivas_Chokkarapu)\
**Post date:** [January 27, 2020, 11:30am UTC](https://forum.ansible.com/t/gcp-how-to-pull-inventory-dynamically-with-multiple-labels-using-inventory-plugins/32063/1 "2020-01-27T11:30:53Z")

</div>

Hi Folks,

I’m using ansible 2.8.4 with Google cloud platform. I’m using **Inventory Plugins** to get the dynamic inventory as ansible recommends.  
I’ve 2 Apache nifi clusters, so I’m pulling inventory using **gcp\_compute**. Each cluster I have a label  
index: 1 and index: 2 so that I can pull vms dynamically based on the index.

plugin inventory:

**plugin: gcp\_compute**  
**projects:**  
**- my-gcp-project**  
**auth\_kind: serviceaccount**  
**keyed\_groups:**  
**- prefix: gcp**  
**key: labels**  
**compose:**  
**ansible\_host: networkInterfaces[0].networkIP**

then I get dynamic groups gcp\_index\_1 and gcp\_index\_2 which I am using in my playbooks. Currently I have 2 playbooks one for the cluster 1 and another for cluster 2.  
In the playbooks I’ve hardcoded those groups like gcp\_index\_1 and gcp\_index\_2 which essential does the same things but deploys on different clusters.

With AWS/Azure, I used Inventory scripts, where I had my groups specified in the hosts file and then used to pull the inventory based on the multiple tags.  
e.g AZURE\_TAGS=stack:dev,index:1 ansible-playbook nifi-install.yml.  
In GCP, I would like to do the same but is there a way to pull inventory with multiple labels so that i can avoid duplication of having separate playbooks for each cluster.  
i.e. I’d like to have one playbook and target which cluster I want to install nifi based on multiple labels.

any suggestions how I go about acheiveing this?

Regards,  
Sreenivas
