# How to make ansible read a json file on remote host?

**URL:** <https://forum.ansible.com/t/how-to-make-ansible-read-a-json-file-on-remote-host/26532>\
**Category:** Ansible Project\
**Created:** [January 22, 2018, 7:32pm UTC](https://forum.ansible.com/t/how-to-make-ansible-read-a-json-file-on-remote-host/26532 "2018-01-22T19:32:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [January 22, 2018, 7:32pm UTC](https://forum.ansible.com/t/how-to-make-ansible-read-a-json-file-on-remote-host/26532/1 "2018-01-22T19:32:20Z")

</div>

I following the technique suggested in [how to read json file using ansible](https://stackoverflow.com/questions/35403769/how-to-read-json-file-using-ansible) suggestion in Stackoverflow, and I do this

`

- set\_fact:  
version\_file: “{{ lookup(‘file’,‘/opt/gitlab/version-manifest.json’) | from\_json }}”  
installed\_version: version\_file.build\_version

`

However I get the error

`  
TASK [gitlab-ce : set\_fact] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[WARNING]: Unable to find ‘/opt/gitlab/version-manifest.json’ in expected  
paths.

fatal: [[host.domain.com](http://host.domain.com)]: FAILED! =\> {“failed”: true, “msg”: “An unhandled exception occurred while running the lookup plugin ‘file’. Error was a \<class ‘ansible.errors.AnsibleError’\>, original message: could not locate file in lookup: /opt/gitlab/version-manifest.json”}  
to retry, use: --limit @/var/tmp/jenkins/team\_SCSCM/gitlab-ce/install-gitlab-ce/ansible-playbooks/gitlab-ce.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[rtp-scm-lnx26.cisco.com](http://rtp-scm-lnx26.cisco.com) : ok=5 changed=0 unreachable=0  
`

The file is there on the remote machine. What gives?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 22, 2018, 8:20pm UTC](https://forum.ansible.com/t/how-to-make-ansible-read-a-json-file-on-remote-host/26532/2 "2018-01-22T20:20:41Z")

</div>

lookups only execute on the local ansible controller.

You will need to use something such as the slurp module to fetch the contents of the file.

- slurp:  
path: /opt/gitlab/version-manifest.json  
register: version\_file

- set\_fact:  
installed\_version: “{{ (version\_file.content|b64decode|from\_json).build\_version }}”

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [January 22, 2018, 9:07pm UTC](https://forum.ansible.com/t/how-to-make-ansible-read-a-json-file-on-remote-host/26532/3 "2018-01-22T21:07:30Z")

</div>

I didn’t know that about lookups. The code you provided worked! Thanks!
