1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Allow to spawn instances without external ip in google cloud module

This commit is contained in:
Lev Popov 2015-03-03 15:15:45 +01:00 committed by Matt Clay
parent 8efb138fdc
commit 6d1fd1afcc

View file

@ -122,6 +122,13 @@ options:
required: false
default: "false"
aliases: []
external_ip:
version_added: "1.9"
description:
- type of external ip, ephemeral by default
required: false
default: "ephemeral"
aliases: []
requirements: [ "libcloud" ]
notes:
@ -230,6 +237,12 @@ def get_instance_info(inst):
key=lambda disk_info: disk_info['index'])]
else:
disk_names = []
if len(inst.public_ips) == 0:
public_ip = None
else:
public_ip = inst.public_ips[0]
return({
'image': not inst.image is None and inst.image.split('/')[-1] or None,
'disks': disk_names,
@ -238,7 +251,7 @@ def get_instance_info(inst):
'name': inst.name,
'network': netname,
'private_ip': inst.private_ips[0],
'public_ip': inst.public_ips[0],
'public_ip': public_ip,
'status': ('status' in inst.extra) and inst.extra['status'] or None,
'tags': ('tags' in inst.extra) and inst.extra['tags'] or [],
'zone': ('zone' in inst.extra) and inst.extra['zone'].name or None,
@ -267,6 +280,10 @@ def create_instances(module, gce, instance_names):
tags = module.params.get('tags')
zone = module.params.get('zone')
ip_forward = module.params.get('ip_forward')
external_ip = module.params.get('external_ip')
if external_ip == "none":
external_ip = None
new_instances = []
changed = False
@ -327,7 +344,8 @@ def create_instances(module, gce, instance_names):
try:
inst = gce.create_node(name, lc_machine_type, lc_image,
location=lc_zone, ex_network=network, ex_tags=tags,
ex_metadata=metadata, ex_boot_disk=pd, ex_can_ip_forward=ip_forward)
ex_metadata=metadata, ex_boot_disk=pd, ex_can_ip_forward=ip_forward,
external_ip=external_ip)
changed = True
except ResourceExistsError:
inst = gce.ex_get_node(name, lc_zone)
@ -418,6 +436,8 @@ def main():
pem_file = dict(),
project_id = dict(),
ip_forward = dict(type='bool', default=False),
external_ip = dict(choices=['ephemeral', 'none'],
default='ephemeral'),
)
)