At Red Hat Tech Day Netherlands 2026 (3 June 2026, Bunnik), the Ansible team announced 12 new content collections landing in AAP 2.7. Among them, google.cloud gets refreshed content spanning Cloud Build 2nd gen, Parameter Manager, Compute, Secret Manager, and Storage. Below is a runnable playbook that provisions a Compute instance and reads a Secret Manager secret to bootstrap it.
Example playbook
---
- name: Provision a GCE instance and inject a secret from Secret Manager
hosts: localhost
connection: local
gather_facts: false
vars:
gcp_project: "my-gcp-project"
gcp_zone: "europe-west4-a"
gcp_region: "europe-west4"
gcp_cred_file: "/etc/ansible/secrets/gcp-sa.json"
instance_name: "web-app-01"
secret_id: "db-password"
tasks:
- name: Fetch the latest version of a Secret Manager secret
google.cloud.gcp_secret_manager_secret_version_info:
secret: "{{ secret_id }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_cred_file }}"
register: db_secret
- name: Create a Compute Engine instance
google.cloud.gcp_compute_instance:
name: "{{ instance_name }}"
machine_type: e2-medium
zone: "{{ gcp_zone }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_cred_file }}"
disks:
- auto_delete: true
boot: true
initialize_params:
source_image: projects/debian-cloud/global/images/family/debian-12
network_interfaces:
- network: null
access_configs:
- name: External NAT
type: ONE_TO_ONE_NAT
metadata:
db-password: "{{ db_secret.payload }}"
labels:
environment: production
managed_by: ansible
status: RUNNING
register: gce_instance
- name: Show the instance's assigned external IP
ansible.builtin.debug:
msg: "{{ gce_instance.networkInterfaces[0].accessConfigs[0].natIP }}"
What it does and why
The first task reads the current version of a Secret Manager secret using gcp_secret_manager_secret_version_info, which is the pattern the refreshed google.cloud collection standardizes on for read-only secret lookups — no need to shell out to gcloud or hardcode credentials in a vars file. The second task uses gcp_compute_instance to create a Debian-based VM, passing the secret's payload into instance metadata so a startup script on the VM can retrieve it locally. This mirrors a common pattern: keep application secrets in Secret Manager, and let the automation layer inject just-in-time values at provisioning time rather than baking them into images or playbooks.
Both modules authenticate with a service account JSON key file via auth_kind: serviceaccount, which is the standard approach for unattended AAP job execution — you'd typically store gcp_cred_file as a machine credential in AAP rather than a plain playbook variable.
Notes
- Module names shown (
gcp_compute_instance,gcp_secret_manager_secret_version_info) follow the collection's existing naming convention; consult the shipped collection docs on your AAP 2.7 instance for the exact parameter set once the refreshed content lands, since Secret Manager and Compute both received expanded module coverage in this release. - Never print
db_secret.payloadwithdebugin a real playbook — treat it as sensitive and mark itno_log: trueon any task that touches it. - Passing secrets through instance metadata is convenient for demos; for production, prefer having the instance's own service account pull the secret directly from Secret Manager at boot, so the value never transits the control node.
- The collection also ships Cloud Build 2nd gen, Parameter Manager, and Storage modules from the same Tech Day Netherlands 2026 announcement — useful for extending this playbook into a full CI/CD-to-provisioning pipeline.
Takeaway
The refreshed google.cloud collection lets a single playbook chain Secret Manager reads directly into Compute provisioning, keeping GCP automation credential-safe and declarative inside AAP 2.7.
Related Articles
- Ansible Playbook Example: Create an S3 Bucket with Encryption
- Ansible Playbook Example: Provision an EC2 Instance with Standard Tags
- Ansible Playbook Example: Request an Azure Resource Group with RBAC