# Dynamic Inventory using Google Cloud Platform

**URL:** <https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801>\
**Category:** Ansible Project\
**Created:** [February 20, 2018, 10:51am UTC](https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801 "2018-02-20T10:51:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chrisy](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Chrisy](https://forum.ansible.com/u/Chrisy)\
**Post date:** [February 20, 2018, 10:51am UTC](https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801/1 "2018-02-20T10:51:21Z")

</div>

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.’

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [February 20, 2018, 11:53am UTC](https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801/2 "2018-02-20T11:53:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisy](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Chrisy](https://forum.ansible.com/u/Chrisy)\
**Post date:** [February 26, 2018, 6:00am UTC](https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801/3 "2018-02-26T06:00:51Z")

</div>

Hi Varun

Thanks for your response!

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

```auto
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....`

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [February 26, 2018, 11:11am UTC](https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801/4 "2018-02-26T11:11:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chrisy](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Chrisy](https://forum.ansible.com/u/Chrisy)\
**Post date:** [March 5, 2018, 9:40am UTC](https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801/5 "2018-03-05T09:40:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [March 5, 2018, 1:36pm UTC](https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801/6 "2018-03-05T13:36:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisy](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Chrisy](https://forum.ansible.com/u/Chrisy)\
**Post date:** [March 5, 2018, 1:47pm UTC](https://forum.ansible.com/t/dynamic-inventory-using-google-cloud-platform/26801/7 "2018-03-05T13:47:38Z")

</div>

Thank you Varun… We will try it out
