Dynamic Inventory using Google Cloud Platform

316 views
Skip to first unread message

Chrisy

unread,
Feb 20, 2018, 5:51:21 AM2/20/18
to Ansible Project
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 <module>
    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.'

Varun Chopra

unread,
Feb 20, 2018, 6:53:21 AM2/20/18
to Ansible Project
'Invalid authorization response, please check your credentials and time drift.'

Chrisy

unread,
Feb 26, 2018, 1:00:51 AM2/26/18
to Ansible Project
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....

Varun Chopra

unread,
Feb 26, 2018, 6:11:43 AM2/26/18
to Ansible Project
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.

On Monday, February 26, 2018 at 11:30:51 AM UTC+5:30, Chrisy wrote:
-wall of text-

Chrisy

unread,
Mar 5, 2018, 4:40:41 AM3/5/18
to Ansible Project
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

Varun Chopra

unread,
Mar 5, 2018, 8:36:34 AM3/5/18
to Ansible Project
Here's a playbook to provision a VM and setup Deluge and a bunch of stuff for seedboxes. https://gist.github.com/chopraaa/5e34b66b155552809261b603a31e7dae

Chrisy

unread,
Mar 5, 2018, 8:47:38 AM3/5/18
to Ansible Project
Thank you Varun... We will try it out
Reply all
Reply to author
Forward
0 new messages