# Creating a GCE instance with reserved ip address

**URL:** <https://forum.ansible.com/t/creating-a-gce-instance-with-reserved-ip-address/23414>\
**Category:** Ansible Project\
**Created:** [January 10, 2017, 10:27am UTC](https://forum.ansible.com/t/creating-a-gce-instance-with-reserved-ip-address/23414 "2017-01-10T10:27:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [January 10, 2017, 10:27am UTC](https://forum.ansible.com/t/creating-a-gce-instance-with-reserved-ip-address/23414/1 "2017-01-10T10:27:01Z")

</div>

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](http://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](http://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](http://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?

---

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [January 10, 2017, 11:38am UTC](https://forum.ansible.com/t/creating-a-gce-instance-with-reserved-ip-address/23414/2 "2017-01-10T11:38:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tom\_Melendez](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@Tom\_Melendez](https://forum.ansible.com/u/Tom_Melendez)\
**Post date:** [January 11, 2017, 1:46am UTC](https://forum.ansible.com/t/creating-a-gce-instance-with-reserved-ip-address/23414/3 "2017-01-11T01:46:49Z")

</div>

Yeah, there’s a PR to address this that’s waiting on me. 🙂  
[https://github.com/ansible/ansible/pull/19701](https://github.com/ansible/ansible/pull/19701)

I’ll get it reviewed this week.

Tom

---

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [January 11, 2017, 6:26am UTC](https://forum.ansible.com/t/creating-a-gce-instance-with-reserved-ip-address/23414/4 "2017-01-11T06:26:22Z")

</div>

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