|
|
@ -222,6 +222,7 @@ class GceInventory(object):
|
|
|
|
'gce_project_id': '',
|
|
|
|
'gce_project_id': '',
|
|
|
|
'gce_zone': '',
|
|
|
|
'gce_zone': '',
|
|
|
|
'libcloud_secrets': '',
|
|
|
|
'libcloud_secrets': '',
|
|
|
|
|
|
|
|
'instance_tags': '',
|
|
|
|
'inventory_ip_type': '',
|
|
|
|
'inventory_ip_type': '',
|
|
|
|
'cache_path': '~/.ansible/tmp',
|
|
|
|
'cache_path': '~/.ansible/tmp',
|
|
|
|
'cache_max_age': '300'
|
|
|
|
'cache_max_age': '300'
|
|
|
@ -247,6 +248,16 @@ class GceInventory(object):
|
|
|
|
if states:
|
|
|
|
if states:
|
|
|
|
self.instance_states = states.split(',')
|
|
|
|
self.instance_states = states.split(',')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set the instance_tags filter, env var overrides config from file
|
|
|
|
|
|
|
|
# and cli param overrides all
|
|
|
|
|
|
|
|
if self.args.instance_tags:
|
|
|
|
|
|
|
|
self.instance_tags = self.args.instance_tags
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.instance_tags = os.environ.get(
|
|
|
|
|
|
|
|
'GCE_INSTANCE_TAGS', config.get('gce', 'instance_tags'))
|
|
|
|
|
|
|
|
if self.instance_tags:
|
|
|
|
|
|
|
|
self.instance_tags = self.instance_tags.split(',')
|
|
|
|
|
|
|
|
|
|
|
|
# Caching
|
|
|
|
# Caching
|
|
|
|
cache_path = config.get('cache', 'cache_path')
|
|
|
|
cache_path = config.get('cache', 'cache_path')
|
|
|
|
cache_max_age = config.getint('cache', 'cache_max_age')
|
|
|
|
cache_max_age = config.getint('cache', 'cache_max_age')
|
|
|
@ -338,6 +349,8 @@ class GceInventory(object):
|
|
|
|
help='List instances (default: True)')
|
|
|
|
help='List instances (default: True)')
|
|
|
|
parser.add_argument('--host', action='store',
|
|
|
|
parser.add_argument('--host', action='store',
|
|
|
|
help='Get all information about an instance')
|
|
|
|
help='Get all information about an instance')
|
|
|
|
|
|
|
|
parser.add_argument('--instance-tags', action='store',
|
|
|
|
|
|
|
|
help='Only include instances with this tags, separated by comma')
|
|
|
|
parser.add_argument('--pretty', action='store_true', default=False,
|
|
|
|
parser.add_argument('--pretty', action='store_true', default=False,
|
|
|
|
help='Pretty format (default: False)')
|
|
|
|
help='Pretty format (default: False)')
|
|
|
|
parser.add_argument(
|
|
|
|
parser.add_argument(
|
|
|
@ -430,6 +443,18 @@ class GceInventory(object):
|
|
|
|
if self.instance_states and not node.extra['status'] in self.instance_states:
|
|
|
|
if self.instance_states and not node.extra['status'] in self.instance_states:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# This check filters on the desired instance tags defined in the
|
|
|
|
|
|
|
|
# config file with the instance_tags config option, env var GCE_INSTANCE_TAGS,
|
|
|
|
|
|
|
|
# or as the cli param --instance-tags.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# If the instance_tags list is _empty_ then _ALL_ instances are returned.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# If the instance_tags list is _populated_ then check the current
|
|
|
|
|
|
|
|
# instance tags against the instance_tags list. If the instance has
|
|
|
|
|
|
|
|
# at least one tag from the instance_tags list, it is returned.
|
|
|
|
|
|
|
|
if self.instance_tags and not set(self.instance_tags) & set(node.extra['tags']):
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
name = node.name
|
|
|
|
name = node.name
|
|
|
|
|
|
|
|
|
|
|
|
meta["hostvars"][name] = self.node_to_dict(node)
|
|
|
|
meta["hostvars"][name] = self.node_to_dict(node)
|
|
|
|