Creating a GCE instance with reserved ip address

I am trying to create a new instance in google compute engine with a reserved external IP address.
Since ansible doesn’t have a module to reserve static IP, I have used gcloud command to do that and then use gce module to create a new instance

Ensure that network and subnet with desired IP range exists

GCE_INI_PATH=inventory/gce.ini ansible all -i inventory/localhost -m gce_net -a “project_id=myproject name=ansiblenet mode=custom ipv4_range=‘172.16.0.0/16’ subnet_name=dev subnet_region=asia-east1 subnet_desc=‘Development area’ state=present” -v

Allow ssh access from outside

GCE_INI_PATH=inventory/gce.ini ansible all -i inventory/localhost -m gce_net -a “project_id=myproject name=ansiblenet mode=custom ipv4_range=‘172.16.0.0/16’ subnet_name=dev subnet_region=asia-east1 subnet_desc=‘Development area’ state=present fwname=allowssh src_range=‘0.0.0.0/0’ allowed=‘tcp:22’” -v

Reserve an IP address

gcloud compute addresses create testing --region=asia-east1

Provision a new instance with reserved IP address

GCE_INI_PATH=inventory/gce.ini ansible all -i inventory/localhost -m gce -a “project_id=myproject name=trial metadata={‘Name’:‘trial’,‘Environment’:‘Development’} machine_type=f1-micro image=debian-8 external_ip=testing tags=‘dev,trial’ network=ansiblenet subnetwork=dev zone=asia-east1-a state=present” -v

The new instance is created but with an ephermal IP address. I tried replacing the name of the external IP with the actual IP address but it still fails to work.

GCE_INI_PATH=inventory/gce.ini ansible all -i inventory/localhost -m gce -a “project_id=myproject name=trial metadata={‘Name’:‘trial’,‘Environment’:‘Development’} machine_type=f1-micro image=debian-8 external_ip=‘104.199.231.152’ tags=‘dev,trial’ network=ansiblenet subnetwork=dev zone=asia-east1-a state=present” -vvvv

I couldn’t find anything in the documentation which could point me to the issue. Am I doing something wrong or is there a bug in the module?

A small update, removing the quotes around the IP Address worked:
GCE_INI_PATH=inventory/gce.ini ansible all -i inventory/localhost -m gce -a “project_id=myproject name=trial metadata={‘Name’:‘trial’,‘Environment’:‘Development’} machine_type=f1-micro image=debian-8 external_ip=104.199.231.152 tags=‘dev,trial’ network=ansiblenet subnetwork=dev zone=asia-east1-a state=present” -vvvv

So, is the named ip address part not supported?

Yeah, there’s a PR to address this that’s waiting on me. :slight_smile:
https://github.com/ansible/ansible/pull/19701

I’ll get it reviewed this week.

Tom

Thank you so much. Looking forward to seeing this fixed.