# SSL error with gce\_instance\_template and ansible

**URL:** <https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760>\
**Category:** Ansible Project\
**Tags:** gcp\
**Created:** [June 19, 2017, 11:46am UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760 "2017-06-19T11:46:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sushrismita.mishra](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@sushrismita.mishra](https://forum.ansible.com/u/sushrismita.mishra)\
**Post date:** [June 19, 2017, 11:46am UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760/1 "2017-06-19T11:46:40Z")

</div>

Hi  
I am a new bee in Ansible. I am trying to manage and create google cloud properties using ansible. However I am getting SSL related errors while connecting.

I tried  
1… downloading the latest cacert.pem from [https://curl.haxx.se/docs/caextract.html](https://curl.haxx.se/docs/caextract.html) and set the variable SSL\_CERT\_FILE.  
2. Downoading cacert from \*[googleapis.google.com](http://googleapis.google.com) with no success

But no success. Could someone please let me know what SSL cert I need to set to get this working ?

Playbook details:

- hosts: localhost

tasks:

- name: create instance template

gce\_instance\_template:

name: case\_mgmt\_template

size: n1-standard-2

image\_family: centos-7-v20170523

state: present

project\_id: “{{ project\_id }}”

credentials\_file: “{{ credentials\_file }}”

service\_account\_email: “{{ service\_account\_email }}”

Error Details:

fatal: [localhost]: FAILED! =\> {

“changed”: false,

“failed”: true

}

MSG:

Unexpected response: ([SSL: CERTIFICATE\_VERIFY\_FAILED] certificate verify failed (\_ssl.c:579)). Detail: Traceback (most recent call last):

File “/tmp/ansible\_M7On7q/ansible\_modlib.zip/ansible/module\_utils/gcp.py”, line 267, in gcp\_connect

project=creds[‘project\_id’])

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/compute/drivers/gce.py”, line 1795, in **init**

super(GCENodeDriver, self). **init** (user\_id, key, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/base.py”, line 948, in **init**

self.connection = self.connectionCls(\*args, \*\*conn\_kwargs)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/compute/drivers/gce.py”, line 99, in **init**

credential\_file=credential\_file, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/google.py”, line 765, in **init**

user\_id, key, auth\_type, credential\_file, scopes, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/google.py”, line 660, in **init**

self.token = self.oauth2\_conn.get\_new\_token()

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/google.py”, line 537, in get\_new\_token

return self.\_token\_request(request)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/google.py”, line 368, in \_token\_request

data=data)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/base.py”, line 603, in request

headers=headers, stream=stream)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/http.py”, line 215, in request

verify=self.verification

File “/usr/lib/python2.7/site-packages/requests/sessions.py”, line 461, in request

resp = self.send(prep, \*\*send\_kwargs)

File “/usr/lib/python2.7/site-packages/requests/sessions.py”, line 573, in send

r = adapter.send(request, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/requests/adapters.py”, line 431, in send

raise SSLError(e, request=request)

SSLError: [SSL: CERTIFICATE\_VERIFY\_FAILED] certificate verify failed (\_ssl.c:579)

Regards,

Sushri

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 20, 2017, 2:11pm UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760/2 "2017-06-20T14:11:23Z")

</div>

What versions do you have of:

\* OS  
\* Ansible  
\* Python

?

---

<div class="post-metadata">

**Author:** ![sushrismita.mishra](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@sushrismita.mishra](https://forum.ansible.com/u/sushrismita.mishra)\
**Post date:** [June 20, 2017, 4:08pm UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760/3 "2017-06-20T16:08:02Z")

</div>

Thank you for your response.  
Please find the below details;

OS: CentOS 7  
Ansible: 2.3.1.0  
Python: 2.7.5

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 20, 2017, 9:25pm UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760/4 "2017-06-20T21:25:04Z")

</div>

Can you run with verbose flags (-vvvv) and what is the output then?

---

<div class="post-metadata">

**Author:** ![sushrismita.mishra](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@sushrismita.mishra](https://forum.ansible.com/u/sushrismita.mishra)\
**Post date:** [June 21, 2017, 4:30am UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760/5 "2017-06-21T04:30:08Z")

</div>

PLease find the verbose output . It does not give much info about the error though.

Loading callback plugin debug of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/ **init**.pyc

PLAYBOOK: createVM.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

1 plays in createVM.yml

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py

\<127.0.0.1\> ESTABLISH LOCAL CONNECTION FOR USER: ansible

\<127.0.0.1\> EXEC /bin/sh -c ‘echo ~ && sleep 0’

\<127.0.0.1\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /opt/ansible/.ansible/tmp/ansible-tmp-1498018836.92-250910727127389`” && echo ansible-tmp-1498018836.92-250910727127389=“`echo /opt/ansible/.ansible/tmp/ansible-tmp-1498018836.92-250910727127389`” ) && sleep 0’

\<127.0.0.1\> PUT /tmp/tmpqriHPk TO /opt/ansible/.ansible/tmp/ansible-tmp-1498018836.92-250910727127389/setup.py

\<127.0.0.1\> EXEC /bin/sh -c ‘chmod u+x /opt/ansible/.ansible/tmp/ansible-tmp-1498018836.92-250910727127389/ /opt/ansible/.ansible/tmp/ansible-tmp-1498018836.92-250910727127389/setup.py && sleep 0’

\<127.0.0.1\> EXEC /bin/sh -c ‘sudo -H -S -n -u root /bin/sh -c ‘"’“‘echo BECOME-SUCCESS-mjlpwykedxecazwcwjlmuxivezlrzfbn; /usr/bin/python2 /opt/ansible/.ansible/tmp/ansible-tmp-1498018836.92-250910727127389/setup.py; rm -rf “/opt/ansible/.ansible/tmp/ansible-tmp-1498018836.92-250910727127389/” \> /dev/null 2\>&1’”’"’ && sleep 0’

ok: [localhost]

META: ran handlers

TASK [create instance template] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

task path: /opt/ansible/gcloud/createVM.yml:8

Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/google/gce\_instance\_template.py

\<127.0.0.1\> ESTABLISH LOCAL CONNECTION FOR USER: ansible

\<127.0.0.1\> EXEC /bin/sh -c ‘echo ~ && sleep 0’

\<127.0.0.1\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /opt/ansible/.ansible/tmp/ansible-tmp-1498018839.89-233748004022392`” && echo ansible-tmp-1498018839.89-233748004022392=“`echo /opt/ansible/.ansible/tmp/ansible-tmp-1498018839.89-233748004022392`” ) && sleep 0’

\<127.0.0.1\> PUT /tmp/tmpEwW49m TO /opt/ansible/.ansible/tmp/ansible-tmp-1498018839.89-233748004022392/gce\_instance\_template.py

\<127.0.0.1\> EXEC /bin/sh -c ‘chmod u+x /opt/ansible/.ansible/tmp/ansible-tmp-1498018839.89-233748004022392/ /opt/ansible/.ansible/tmp/ansible-tmp-1498018839.89-233748004022392/gce\_instance\_template.py && sleep 0’

\<127.0.0.1\> EXEC /bin/sh -c ‘sudo -H -S -n -u root /bin/sh -c ‘"’“‘echo BECOME-SUCCESS-xifpovkgfndyqgmzlspifcobymolqzoi; /usr/bin/python2 /opt/ansible/.ansible/tmp/ansible-tmp-1498018839.89-233748004022392/gce\_instance\_template.py; rm -rf “/opt/ansible/.ansible/tmp/ansible-tmp-1498018839.89-233748004022392/” \> /dev/null 2\>&1’”’"’ && sleep 0’

fatal: [localhost]: FAILED! =\> {

“changed”: false,

“failed”: true,

“invocation”: {

“module\_args”: {

“automatic\_restart”: null,

“can\_ip\_forward”: false,

“credentials\_file”: “/opt/ansible/gcloud/.cred/case-mgmt-dev-f452642d06ab.json”,

“description”: null,

“disk\_auto\_delete”: true,

“disk\_type”: “pd-standard”,

“disks”: null,

“external\_ip”: “ephemeral”,

“image”: null,

“image\_family”: “centos-7-v20170523”,

“metadata”: null,

“name”: “case\_mgmt\_template”,

“network”: “default”,

“nic\_gce\_struct”: null,

“pem\_file”: null,

“preemptible”: null,

“project\_id”: “case-mgmt-dev”,

“service\_account\_email”: “replaced the service account details”,

“service\_account\_permissions”: null,

“size”: “n1-standard-2”,

“source”: null,

“state”: “present”,

“subnetwork”: null,

“tags”: null

}

}

}

MSG:

Unexpected response: ([SSL: CERTIFICATE\_VERIFY\_FAILED] certificate verify failed (\_ssl.c:579)). Detail: Traceback (most recent call last):

File “/tmp/ansible\_P8l394/ansible\_modlib.zip/ansible/module\_utils/gcp.py”, line 267, in gcp\_connect

project=creds[‘project\_id’])

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/compute/drivers/gce.py”, line 1795, in **init**

super(GCENodeDriver, self). **init** (user\_id, key, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/base.py”, line 948, in **init**

self.connection = self.connectionCls(\*args, \*\*conn\_kwargs)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/compute/drivers/gce.py”, line 99, in **init**

credential\_file=credential\_file, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/google.py”, line 765, in **init**

user\_id, key, auth\_type, credential\_file, scopes, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/google.py”, line 660, in **init**

self.token = self.oauth2\_conn.get\_new\_token()

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/google.py”, line 537, in get\_new\_token

return self.\_token\_request(request)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/google.py”, line 368, in \_token\_request

data=data)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/common/base.py”, line 603, in request

headers=headers, stream=stream)

File “/usr/lib/python2.7/site-packages/apache\_libcloud-2.0.0-py2.7.egg/libcloud/http.py”, line 215, in request

verify=self.verification

File “/usr/lib/python2.7/site-packages/requests/sessions.py”, line 461, in request

resp = self.send(prep, \*\*send\_kwargs)

File “/usr/lib/python2.7/site-packages/requests/sessions.py”, line 573, in send

r = adapter.send(request, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/requests/adapters.py”, line 431, in send

raise SSLError(e, request=request)

SSLError: [SSL: CERTIFICATE\_VERIFY\_FAILED] certificate verify failed (\_ssl.c:579)

---

<div class="post-metadata">

**Author:** ![sushrismita.mishra](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@sushrismita.mishra](https://forum.ansible.com/u/sushrismita.mishra)\
**Post date:** [July 3, 2017, 12:05pm UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760/6 "2017-07-03T12:05:46Z")

</div>

It seems it is happening with all the GCE module , I am trying to excute. Even ./gce.py --list gives the same error.  
After searching couple of blogs , I managed to get rid of the error , however a new error has appeared now.

To fix I installed: pip install pyOpenSSL ndg-httpsclient pyasn1

Now the new errors are:

Traceback (most recent call last):

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

GceInventory()

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

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

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

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

File “/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py”, line 1795, in **init**

super(GCENodeDriver, self). **init** (user\_id, key, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/libcloud/common/base.py”, line 952, in **init**

self.connection = self.connectionCls(\*args, \*\*conn\_kwargs)

File “/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py”, line 99, in **init**

credential\_file=credential\_file, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/libcloud/common/google.py”, line 765, in **init**

user\_id, key, auth\_type, credential\_file, scopes, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/libcloud/common/google.py”, line 660, in **init**

self.token = self.oauth2\_conn.get\_new\_token()

File “/usr/lib/python2.7/site-packages/libcloud/common/google.py”, line 537, in get\_new\_token

return self.\_token\_request(request)

File “/usr/lib/python2.7/site-packages/libcloud/common/google.py”, line 368, in \_token\_request

data=data)

File “/usr/lib/python2.7/site-packages/libcloud/common/base.py”, line 607, in request

headers=headers, stream=stream)

File “/usr/lib/python2.7/site-packages/libcloud/http.py”, line 215, in request

verify=self.verification

File “/usr/lib/python2.7/site-packages/requests/sessions.py”, line 465, in request

resp = self.send(prep, \*\*send\_kwargs)

File “/usr/lib/python2.7/site-packages/requests/sessions.py”, line 573, in send

r = adapter.send(request, \*\*kwargs)

File “/usr/lib/python2.7/site-packages/requests/adapters.py”, line 370, in send

timeout=timeout

File “/usr/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py”, line 544, in urlopen

body=body, headers=headers)

File “/usr/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py”, line 344, in \_make\_request

self.\_raise\_timeout(err=e, url=url, timeout\_value=conn.timeout)

File “/usr/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py”, line 314, in \_raise\_timeout

if ‘timed out’ in str(err) or ‘did not complete (read)’ in str(err): # Python 2.6

The connectivity is not an issue , as I am able to perform all the operations using gcloud command.  
Any help will be appreciated, as it is been a long time I am struggling with this.

---

<div class="post-metadata">

**Author:** ![sushrismita.mishra](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@sushrismita.mishra](https://forum.ansible.com/u/sushrismita.mishra)\
**Post date:** [July 4, 2017, 10:39am UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760/7 "2017-07-04T10:39:01Z")

</div>

If anyone is facing the same issue , hope this will solve the issue

the certifi==2015.04.28 version fixed the issue with google modules. Not sure at this point , if it broke anything else.

Reference URL: [https://github.com/omab/python-social-auth/issues/566](https://github.com/omab/python-social-auth/issues/566)

---

<div class="post-metadata">

**Author:** ![valex](https://avatars.discourse-cdn.com/v4/letter/v/94ad74/32.png) [@valex](https://forum.ansible.com/u/valex)\
**Post date:** [November 23, 2017, 4:09am UTC](https://forum.ansible.com/t/ssl-error-with-gce-instance-template-and-ansible/24760/8 "2017-11-23T04:09:06Z")

</div>

Hi,

You may need to enter the value of playbook variable ‘service\_account\_email’ as the one which mentioned in the ‘json’ credential file.
