From 67dc8c146e006fdfef7504c2d9e0a671c8d5e7d9 Mon Sep 17 00:00:00 2001 From: Markus Liljedahl Date: Thu, 16 Mar 2017 13:28:30 +0100 Subject: [PATCH] Added support for specifying zone for gce dynamic inventory (#20938) --- contrib/inventory/gce.ini | 9 +++++---- contrib/inventory/gce.py | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/contrib/inventory/gce.ini b/contrib/inventory/gce.ini index 488e838a22d..24cf28ea390 100644 --- a/contrib/inventory/gce.ini +++ b/contrib/inventory/gce.ini @@ -37,13 +37,14 @@ # statement in the inventory script. However, you can specify an absolute # path to the secrets.py file with 'libcloud_secrets' parameter. # This option will be deprecated in a future release. -libcloud_secrets = +libcloud_secrets = # If you are not going to use a 'secrets.py' file, you can set the necessary # authorization parameters here. -gce_service_account_email_address = -gce_service_account_pem_file_path = -gce_project_id = +gce_service_account_email_address = +gce_service_account_pem_file_path = +gce_project_id = +gce_zone = # Filter inventory based on on state. Leave undefined to return instances regardless of state. # example: Uncomment to only return inventory in the running or provisioning state diff --git a/contrib/inventory/gce.py b/contrib/inventory/gce.py index 5c5814635c4..63c852524a0 100755 --- a/contrib/inventory/gce.py +++ b/contrib/inventory/gce.py @@ -217,6 +217,7 @@ class GceInventory(object): 'gce_service_account_email_address': '', 'gce_service_account_pem_file_path': '', 'gce_project_id': '', + 'gce_zone': '', 'libcloud_secrets': '', 'inventory_ip_type': '', 'cache_path': '~/.ansible/tmp', @@ -296,13 +297,15 @@ class GceInventory(object): self.config.get('gce','gce_service_account_email_address'), self.config.get('gce','gce_service_account_pem_file_path') ] - kwargs = {'project': self.config.get('gce', 'gce_project_id')} + kwargs = {'project': self.config.get('gce', 'gce_project_id'), + 'datacenter': self.config.get('gce', 'gce_zone')} # If the appropriate environment variables are set, they override # other configuration; process those into our args and kwargs. args[0] = os.environ.get('GCE_EMAIL', args[0]) args[1] = os.environ.get('GCE_PEM_FILE_PATH', args[1]) kwargs['project'] = os.environ.get('GCE_PROJECT', kwargs['project']) + kwargs['datacenter'] = os.environ.get('GCE_ZONE', kwargs['datacenter']) # Retrieve and return the GCE driver. gce = get_driver(Provider.GCE)(*args, **kwargs)