3

I am currently struggling to configure Cloud NAT in gcp via ansible.

I was able to set up the Cloud NAT as described in the documentation: https://cloud.google.com/nat/docs/gke-example with gcloud commands, doing basically the three steps create bastion, create router, configure NAT of created router, which worked as expected.

Therefore, I executed the following commands manually:

  • gcloud compute instances create bastion-1...
  • gcloud compute routers create nat-router...
  • gcloud compute routers nats create nat-config...

The ... is the rest of the commands with region etc which are probably not needed for the question.

Now I want to create an ansible role to do the same. Currently, I was able to create the bastion host via the modules:

  • gcp_compute_disk
  • gcp_compute_network
  • gcp_compute_instance

and the router itself via

  • gcp_compute_router

so step 1 and 2 are done. However, I cannot figure out, if the NAT for the router can be configured via ansible. I couldn't find a corresponding module in the google cloud module list https://docs.ansible.com/ansible/latest/modules/list_of_cloud_modules.html#google or relevant fields to set in the gcp_compute_router-module https://docs.ansible.com/ansible/latest/modules/gcp_compute_router_module.html#gcp-compute-router-module.

Now my question is: Is it possible to configure gcp Cloud NAT via ansible, and if so, do I have to execute shell commands in my playbook or are there modules I can use? Am I overlooking something?

If any information is missing or irrelevant, or I should extend the example code parts, please let me know, so I can edit my question.

Thomas Böhm
  • 145
  • 1
  • 8

1 Answers1

2

It's seems Ansible doesn't have implemented that functions in the present modules for GCP. You can work around this by running the explicit gcp commands to complete the missing steps, on the machine running Ansible as a command on your playbook, check these examples

DavidC
  • 166
  • 3