docker_login and GCR

517 views
Skip to first unread message

Dmitry Makovey

unread,
Sep 1, 2016, 7:03:18 PM9/1/16
to Ansible Project
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" 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?

julien singler

unread,
Jun 19, 2017, 11:36:01 AM6/19/17
to Ansible Project
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 .. 

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 :)

Dimon

unread,
Jun 19, 2017, 12:41:55 PM6/19/17
to julien singler, Ansible Project
That is a neat trick :) will try it next time I'm around GCP project.

Thanks Julien!
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Nicholas Manning

unread,
Feb 18, 2018, 4:04:09 PM2/18/18
to Ansible Project
This really saved me. Thank you!

For others, an example:

- 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
Reply all
Reply to author
Forward
0 new messages