From 16f66a39a6ec8ce5c041c8f08ed2b017b409885d Mon Sep 17 00:00:00 2001 From: rncry Date: Wed, 17 Jun 2015 17:22:28 +0100 Subject: [PATCH] support instances with no public ip default to private ip if the instance doesn't have a public ip assigned. (causes list index out of range error otherwise) --- plugins/inventory/gce.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inventory/gce.py b/plugins/inventory/gce.py index 76e14f23012..5fe3db93f8e 100755 --- a/plugins/inventory/gce.py +++ b/plugins/inventory/gce.py @@ -221,7 +221,7 @@ class GceInventory(object): 'gce_image': inst.image, 'gce_machine_type': inst.size, 'gce_private_ip': inst.private_ips[0], - 'gce_public_ip': inst.public_ips[0], + 'gce_public_ip': inst.public_ips[0] if len(inst.public_ips) >= 1 else None, 'gce_name': inst.name, 'gce_description': inst.extra['description'], 'gce_status': inst.extra['status'], @@ -230,7 +230,7 @@ class GceInventory(object): 'gce_metadata': md, 'gce_network': net, # Hosts don't have a public name, so we add an IP - 'ansible_ssh_host': inst.public_ips[0] + 'ansible_ssh_host': inst.public_ips[0] if len(inst.public_ips) >= 1 else inst.private_ips[0] } def get_instance(self, instance_name):