# docker\_login and GCR

**URL:** <https://forum.ansible.com/t/docker-login-and-gcr/22459>\
**Category:** Ansible Project\
**Created:** [September 1, 2016, 11:03pm UTC](https://forum.ansible.com/t/docker-login-and-gcr/22459 "2016-09-01T23:03:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [September 1, 2016, 11:03pm UTC](https://forum.ansible.com/t/docker-login-and-gcr/22459/1 "2016-09-01T23:03:18Z")

</div>

is anyone using docker\_login with Google Cloud Registry?

I am attempting to do so by defining variable for auth token:

`  
gcloud\_token\_file: gcp\_sa\_account.json  
gcloud\_token: “{{ lookup(‘file’, gcloud\_token\_file) }}”

`

and then trying to login:

`  
docker\_login: username=“\_json\_key” password=“{{ gcloud\_token | to\_json | quote }}” email=“{{ docker\_auth\_email }}” registry=“[gcr.io](http://gcr.io)” reauthorize=“yes”

`

it looks like ansible instead of picking up “raw” contents of the file auto-converts it into structure as soon as it notices JSON so I have to “un-convert” it with to\_json, however as soon as I do that it seems like escaping/quoting goes out the window and I am unable to get login to work as expected. Using the same gcp\_sa\_account.json I can login just find using

`docker login -e some@email.com -u _json_key -p "$(cat gcp_sa_account.json)" https://gcr.io`

I looked online and couldn’t find any samples of people using it. is it just not meant to be functional with GCR?

---

<div class="post-metadata">

**Author:** ![julien\_singler](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@julien\_singler](https://forum.ansible.com/u/julien_singler)\
**Post date:** [June 19, 2017, 1:25pm UTC](https://forum.ansible.com/t/docker-login-and-gcr/22459/2 "2017-06-19T13:25:41Z")

</div>

Hi Dmitry,

Almost a year after you, I’ve the same problem. I guess you fixed your problem another way, but for anyone that is currently in the same situation, I found a trick to not let the lookup interpret your json …

By digging on this forum : [https://groups.google.com/forum/#!topic/ansible-devel/2C7pl2\_kxlY](https://groups.google.com/forum/#!topic/ansible-devel/2C7pl2_kxlY)  
They suggests to put a space between your double quote and the accolades :  
gcloud\_token: " {{lookup(‘file’, gcloud\_token\_file)}}"

And it’s working fine with gcr … No need for your filters like to\_json and quote.  
I hope it will help others 🙂

---

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [June 19, 2017, 4:33pm UTC](https://forum.ansible.com/t/docker-login-and-gcr/22459/3 "2017-06-19T16:33:55Z")

</div>

That is a neat trick 🙂 will try it next time I’m around GCP project.

Thanks Julien!

---

<div class="post-metadata">

**Author:** ![Nicholas\_Manning](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Nicholas\_Manning](https://forum.ansible.com/u/Nicholas_Manning)\
**Post date:** [February 18, 2018, 9:04pm UTC](https://forum.ansible.com/t/docker-login-and-gcr/22459/4 "2018-02-18T21:04:08Z")

</div>

This really saved me. Thank you!

For others, an example:

```auto
- name: Log into private registry and force re-authorization
  become: true
  docker_login:
    registry: "{{ docker_repo_hostname }}"
    username: "{{ docker_repo_user }}"
    password: " {{ lookup('file', 'gcr-user.json') }}"
    reauthorize: yes

```
