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

240 views
Skip to first unread message

Sreenivas Chokkarapu

unread,
Jan 27, 2020, 6:30:53 AM1/27/20
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages