ansible and gce.py

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

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 #################

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