Affichage des articles dont le libellé est google cloud. Afficher tous les articles
Affichage des articles dont le libellé est google cloud. Afficher tous les articles

lundi 8 septembre 2025

Ansible : GCP Google Cloud (Compute) ansible dynamic inventory with cache

Inventory definition GCP compute

---
plugin: google.cloud.gcp_compute
# https://docs.ansible.com/ansible/latest/collections/google/cloud/gcp_compute_inventory.html
# https://gitlab.com/gitlab-org/gitlab-environment-toolkit/-/blob/main/docs/environment_configure.md#google-cloud-platform-gcp

projects:
- project_id

auth_kind: serviceaccount
# must match `ansible_user` below, cf. other article on how to set this up
service_account_file: ./gcp-sa.json

filters:
# only return running instances, we won't be able to connect to sopped instances
- status = RUNNING
# for example, only return compute instances with label foo = foobar
- labels.foo = foobar

keyed_groups:
- key: labels
prefix: label

hostnames:
- name
- public_ip
- private_ip

compose:
#<ansible variable to be set> <data from gcp discovery>
# Set an inventory parameter to use the Public IP address to connect to the host
#ansible_host: public_ip
ansible_host: networkInterfaces[0].accessConfigs[0].natIP
ansible_user: "'sa_115528571027174573787'"

# GCP compute label "activate_this" value => ansible variable "run_this" value
run_this: labels['activate_this']