Reading a Json file using Ansible

614 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 like below called "develop.json"

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

Below is my ansible script. I need to fetch release_name from the file.

---
  - 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 this is not working. Kindly help me.


Brian Coca

unread,
May 6, 2016, 9:46:18 AM5/6/16
to ansible...@googlegroups.com
Just use it as a vars file.

vars_file: 
  - '/opt/develop.json'

or via the include_vars module, JSON is a subset of YAML so it can be read as you would any other vars file.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7afb6ba8-3d29-4eac-9920-6a1c2bc65b5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages