google-cloud-platformansible

Ansible GCP IAP tunnel


I’m trying to connect to a GCP compute instance through IAP. I have a service account with permissions.

I have tried the following

  1. Basic ansible ping,ansible -vvvv GCP -m ping, which errors because the host name is not found bc I do not have an external ip
  2. I have set ssh_executeable=wrapper.sh like here

Number 2 is almost working but regexing commands are hacky.

Is there a native ansible solution?

Edit: The gcp_compute dynamic inventory does work for pinging instances but it does not work for managing the instances.

Ansible does NOT support package or system management while tunneling through IAP.


Solution

  • (Converting my comment as an answer as requested by OP)

    Ansible has a native gce dynamic inventory plugin that you should use to connect to your instances.