# using json as a password for docker\_login module

**URL:** <https://forum.ansible.com/t/using-json-as-a-password-for-docker-login-module/31631>\
**Category:** Ansible Project\
**Created:** [November 10, 2019, 12:46pm UTC](https://forum.ansible.com/t/using-json-as-a-password-for-docker-login-module/31631 "2019-11-10T12:46:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user57](https://avatars.discourse-cdn.com/v4/letter/u/e480ec/32.png) [@user57](https://forum.ansible.com/u/user57)\
**Post date:** [November 10, 2019, 12:46pm UTC](https://forum.ansible.com/t/using-json-as-a-password-for-docker-login-module/31631/1 "2019-11-10T12:46:48Z")

</div>

I already asked that question on ansible-devel mailing list: [https://groups.google.com/forum/#!msg/ansible-devel/aXyKGHRtDcQ/GvUxgopZAQAJ](https://groups.google.com/forum/#!msg/ansible-devel/aXyKGHRtDcQ/GvUxgopZAQAJ)

I am trying to log into private docker container registry and I need to use a json-string as a password. So I do the following  
`

docker\_login:  
registry: cr.yandex  
username: json\_key  
password: “{{ lookup(‘file’, ‘key.json’) }}”  
reauthorize: yes

`  
And I got an error “Get [https://cr.yandex/v2/](https://cr.yandex/v2/): unauthorized: Password is invalid - must be JSON key”.

When I ran “ansible-playbook” in verbose mode I saw that the content of the file “key.json” was transcoded – double quotes were changed to single quotes so it have become an invalid json string.  
Felix Fontein from ansible-devel mailing list pointed that the problem is that Ansible interprets JSON file as a dictionary, parses it and passes it on as a dictionary.

Is there any way to tell Ansible not to parse .json file to dictionary and keep it as a string?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 10, 2019, 3:01pm UTC](https://forum.ansible.com/t/using-json-as-a-password-for-docker-login-module/31631/2 "2019-11-10T15:01:55Z")

</div>

If you are using Jinja2 2.10 or newer you could set it to preserve the variable by setting ANSIBLE\_JINJA2\_NATIVE[1]

Add to the task  
&nbsp;&nbsp;&nbsp;environment:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ANSIBLE\_JINJA2\_NATIVE: 1

In my limited testing of Jinja native I haven't gotten the environment inside Ansible to work, it does worked when setting it on command line like so

&nbsp;&nbsp;&nbsp;ANSIBLE\_JINJA2\_NATIVE=1 ansible-playbook \<playbook\>

but then it's set for every task.

[1] [https://docs.ansible.com/ansible/latest/reference\_appendices/config.html#default-jinja2-native](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-jinja2-native)

---

<div class="post-metadata">

**Author:** ![user57](https://avatars.discourse-cdn.com/v4/letter/u/e480ec/32.png) [@user57](https://forum.ansible.com/u/user57)\
**Post date:** [November 12, 2019, 6:20pm UTC](https://forum.ansible.com/t/using-json-as-a-password-for-docker-login-module/31631/3 "2019-11-12T18:20:09Z")

</div>

I added “jinja2\_native = 1” to ansible.cfg and everything worked! Thanks a lot!
