The best way to manage and orchestrate VM instances in Google cloud using Ansible is through Dynamic inventory plugin. It is an ansible google cloud module that authenticates GCP in run time and returns the instance details.
With dynamic inventory, you don’t need to manage a static inventory file, instead, you can group instances based on instance labels, zones, and network tags. Even you can group instances based on names.
Ansible Dynamic Inventory Google Cloud Configuration
Let’s get started.
- You should have pip installed
- Ansible installed
- Google Service Account JSON with permissions to provision GCP resources.
Follow the steps given below to configure Ansible dynamic inventroy GCP plugin,
Step 1: Install google-auth module using pip.
sudo pip install requests google-auth
Step 2: Create a dedicated inventory directory
sudo mkdir -p /opt/ansible/inventory
Step 3: Create a Google IAM service account. It will be used by the Ansible server to authenticate against…