Creating a GCE instance with reserved ip address

123 views
Skip to first unread message

Mehul Ved

unread,
Jan 10, 2017, 5:27:26 AM1/10/17
to ansible...@googlegroups.com
 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?
--
With Regards,
Mehul Ved

Mehul Ved

unread,
Jan 10, 2017, 6:38:53 AM1/10/17
to ansible...@googlegroups.com
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?

Tom Melendez

unread,
Jan 10, 2017, 8:46:49 PM1/10/17
to Ansible Project


On Tuesday, January 10, 2017 at 3:38:53 AM UTC-8, Mehul Ved wrote:
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. :-)
https://github.com/ansible/ansible/pull/19701

I'll get it reviewed this week.

Tom

Mehul Ved

unread,
Jan 11, 2017, 1:26:46 AM1/11/17
to ansible...@googlegroups.com
Thank you so much. Looking forward to seeing this fixed.
Reply all
Reply to author
Forward
0 new messages