how to read json file using ansible
In case if you need to read a JSON
formatted text and store it as a variable, it can be also handled by include_vars
.
- hosts: localhost
tasks:
- include_vars:
file: variable-file.json
name: variable
- debug: var=variable
You have to add a from_json
jinja2 filter after the lookup:
version_file: "{{ lookup('file','/home/shasha/devOps/tests/packageFile.json') | from_json }}"