Access same variable with different value from multiple json files

9 views
Skip to first unread message

Coding

unread,
Jan 28, 2019, 9:20:53 PM1/28/19
to Ansible Project
I have multiple json files look like this:
temp/file-a.json:
{
“x”: 5”,
“y”: “name1”,
}

tmp/file-b.jsob:
{
“x”: “10”,
“y”: “name2”,
}

tmp/file-c.json:
{
“x”: “7”,
“y”: “name3”,
}

....... and more

All json files are on the same server where I place my playbook. My goal is to access variable x from each json file. If x<6, I will copy json file to another remote hostA. I can use the following playbook to achieve my goal for single json file:

—-
- hosts: hostA
tasks:
- include_vars:
file: tmp/file-a.json
name: my_var

- name: copy files to hostA
copy:
src=tmp/file-a.json
dest=/hostA/tmp/
when: “{{ my_var.x|int }} “< 6

How do I do this for all json files under tmp/ directory?

Reply all
Reply to author
Forward
0 new messages