Reading a json file using Ansible

99 views
Skip to first unread message

Shwetha Hadimani

unread,
May 6, 2016, 9:33:15 AM5/6/16
to Ansible Project
Hi,

I have  a json file called "develop.json" like below,

{
    "releasedata": {
        "release_name": "abcd",
        "release_number": "22"
    }
}

I want to read this file in ansible and get the value for "release_name" key. I have tried the below code

---
  - hosts: localhost
    vars:
       version_file: "{{ lookup('file', '/opt/develop.json')  | from_json }}"
    tasks:
       - name: print json file
        debug: msg= "{{ version_file.releasedata.release_name }}"

But I am getting this error:
 {"failed": true, "msg": "the field 'args' has an invalid value ([]), and could not be converted to an dict

So I am assuming this is not the right way to read a json file in ansible. Kindly tell me the right way to read a json file. Thank you.

Reply all
Reply to author
Forward
0 new messages