Dynamic Inventory using Google Cloud Platform

We are trying to configure Google compute engine resources using dynamic inventory in ANSIBLE

We are getting the below error when we run the command: $ ./gce.py --list

File “./gce.py”, line 508, in
GceInventory()
File “./gce.py”, line 170, in init
self.driver = self.get_gce_driver()
File “./gce.py”, line 318, in get_gce_driver
gce = get_driver(Provider.GCE)(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/libcloud/compute/drivers/gce.py”, line 1058, in init
self.zone_list = self.ex_list_zones()
File “/usr/local/lib/python2.7/dist-packages/libcloud/compute/drivers/gce.py”, line 1790, in ex_list_zones
response = self.connection.request(request, method=‘GET’).object
File “/usr/local/lib/python2.7/dist-packages/libcloud/compute/drivers/gce.py”, line 120, in request
response = super(GCEConnection, self).request(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/libcloud/common/google.py”, line 718, in request
args, *kwargs)
File “/usr/local/lib/python2.7/dist-packages/libcloud/common/base.py”, line 748, in request
params, headers = self.pre_connect_hook(params, headers)
File “/usr/local/lib/python2.7/dist-packages/libcloud/compute/drivers/gce.py”, line 109, in pre_connect_hook
headers)
File “/usr/local/lib/python2.7/dist-packages/libcloud/common/google.py”, line 697, in pre_connect_hook
self._refresh_oauth2_token()
File “/usr/local/lib/python2.7/dist-packages/libcloud/common/google.py”, line 772, in _refresh_oauth2_token
self.oauth2_token = self.oauth2_conn.refresh_token(self.oauth2_token)
File “/usr/local/lib/python2.7/dist-packages/libcloud/common/google.py”, line 382, in refresh_token
return self.get_new_token()
File “/usr/local/lib/python2.7/dist-packages/libcloud/common/google.py”, line 530, in get_new_token
return self._token_request(request)
File “/usr/local/lib/python2.7/dist-packages/libcloud/common/google.py”, line 360, in _token_request
raise GoogleAuthError('Invalid authorization response, please ’
libcloud.common.google.GoogleAuthError: ‘Invalid authorization response, please check your credentials and time drift.’

‘Invalid authorization response, please check your credentials and time drift.’

Hi Varun

Thanks for your response!

We are getting the below error when we run the command: $ GCE_INI_PATH=.gce.ini ./gce.py

Traceback (most recent call last):
  File "./gce.py", line 297, in <module>
    GceInventory()
  File "./gce.py", line 111, in __init__
    self.driver = self.get_gce_driver()
  File "./gce.py", line 187, in get_gce_driver
    gce = get_driver(Provider.GCE)(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/libcloud/compute/drivers/gce.py", line 878, in __init__
    raise ValueError('Project name must be specified using '
ValueError: Project name must be specified using "project" keyword.

Pl advise us....

Keep gce.ini and gce.py in your inventory, make sure gce.ini has values for gce_service_account_email_address, gce_service_account_pem_file_path and gce_project_id.

After that, gce.py --list-hosts should work.

Hi Varun,

Thank you…We could get that issue resolved. Can you please give us a sample playbook to install these applications(like apache, python, etc…) in the VM running in the GCP from ansible

Thank You

Here’s a playbook to provision a VM and setup Deluge and a bunch of stuff for seedboxes. https://gist.github.com/chopraaa/5e34b66b155552809261b603a31e7dae

Thank you Varun… We will try it out