# ansible and gce.py

**URL:** <https://forum.ansible.com/t/ansible-and-gce-py/17199>\
**Category:** Ansible Project\
**Created:** [January 6, 2015, 8:53pm UTC](https://forum.ansible.com/t/ansible-and-gce-py/17199 "2015-01-06T20:53:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Mooshammer](https://avatars.discourse-cdn.com/v4/letter/p/c5a1d2/32.png) [@Peter\_Mooshammer](https://forum.ansible.com/u/Peter_Mooshammer)\
**Post date:** [January 6, 2015, 8:53pm UTC](https://forum.ansible.com/t/ansible-and-gce-py/17199/1 "2015-01-06T20:53:42Z")

</div>

Hi there,

I assume I am missing a step in the setup:

1.) I set:

ANSIBLE\_HOSTS=/…/ansible/gce.py

this files copied from the 1.8.2 branch …/plugins/inventory/gce.py

libcloud is installed with pip.

PYTHONPATH=/…/ansible

The secrets.py seems be correct as I can create a vm with a static hosts file.

What happens is:

./gce.py --list

Traceback (most recent call last):

File “./gce.py”, line 287, in

GceInventory()

File “./gce.py”, line 101, in **init**

self.driver = self.get\_gce\_driver()

File “./gce.py”, line 177, in get\_gce\_driver

gce = get\_driver(Provider.GCE)(\*args, \*\*kwargs)

File “/Library/Python/2.7/site-packages/libcloud/compute/drivers/gce.py”, line 605, in **init**

self.zone\_list = self.ex\_list\_zones()

File “/Library/Python/2.7/site-packages/libcloud/compute/drivers/gce.py”, line 936, in ex\_list\_zones

response = self.connection.request(request, method=‘GET’).object

File “/Library/Python/2.7/site-packages/libcloud/common/google.py”, line 669, in request

\*args, \*\*kwargs)

File “/Library/Python/2.7/site-packages/libcloud/common/base.py”, line 696, in request

params, headers = self.pre\_connect\_hook(params, headers)

File “/Library/Python/2.7/site-packages/libcloud/common/google.py”, line 645, in pre\_connect\_hook

self.token\_info = self.auth\_conn.refresh\_token(self.token\_info)

File “/Library/Python/2.7/site-packages/libcloud/common/google.py”, line 369, in refresh\_token

return self.get\_new\_token()

File “/Library/Python/2.7/site-packages/libcloud/common/google.py”, line 501, in get\_new\_token

return self.\_token\_request(request)

File “/Library/Python/2.7/site-packages/libcloud/common/google.py”, line 348, in \_token\_request

response = self.request(‘/o/oauth2/token’, method=‘POST’, data=data)

File “/Library/Python/2.7/site-packages/libcloud/common/base.py”, line 736, in request

response = responseCls(\*\*kwargs)

File “/Library/Python/2.7/site-packages/libcloud/common/base.py”, line 119, in **init**

self.object = self.parse\_body()

File “/Library/Python/2.7/site-packages/libcloud/common/google.py”, line 263, in parse\_body

(code, message) = self.\_get\_error(body)

File “/Library/Python/2.7/site-packages/libcloud/common/google.py”, line 204, in \_get\_error

code = err.get(‘reason’, None)

AttributeError: ‘str’ object has no attribute ‘get’

Anything I may have done wrong?

thanks

Peter

---

<div class="post-metadata">

**Author:** ![kesten\_broughton1](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kesten\_broughton1](https://forum.ansible.com/u/kesten_broughton1)\
**Post date:** [January 7, 2015, 6:27pm UTC](https://forum.ansible.com/t/ansible-and-gce-py/17199/2 "2015-01-07T18:27:34Z")

</div>

Hi Peter,

I tried the secrets.py way and got the same error.  
I did get things working by setting the GCE\_INI\_PATH

> cat $GCE\_INI\_PATH  
> [gce]

# You can find your generated gce\_service\_account\_email\_address on the compute web console

gce\_service\_account\_email\_address = 10\*\*\*\*\*\*\*\*\*\*\*\*\*redacted#####k1@developer.gserviceaccount.com  
I may also be allowed to use your personal account, but haven’t verified.  
#gce\_service\_account\_email\_address = @gmail.com

# You can download creds and possible convert pkcs12 to pem format according to the GCE authorization docs

gce\_service\_account\_pem\_file\_path = /user/space/path/to/your/\<project\_key\>.pem

# gce\_project\_id is the name gcloud console generated for you, not the name you gave the project.

# Check on the console web page

gce\_project\_id =

############# END OF FILE #################

---

<div class="post-metadata">

**Author:** ![Peter\_Mooshammer](https://avatars.discourse-cdn.com/v4/letter/p/c5a1d2/32.png) [@Peter\_Mooshammer](https://forum.ansible.com/u/Peter_Mooshammer)\
**Post date:** [January 7, 2015, 9:43pm UTC](https://forum.ansible.com/t/ansible-and-gce-py/17199/3 "2015-01-07T21:43:14Z")

</div>

Hi Kesten,

should have updated the thread. I had a typo in the email address required for authentication. Stupid - but they don’t really check if you are able to authenticate. So when auth fails there is an empty or no json object returned and we see this error …

What I did: I dont use GCE\_INI\_PATH, I only use PYTHONPATH and point it the dir that contains secrets.py.

gce.ini isn’t really used that much unlike ec2.ini

Hope this helps

Peter
