Coding
unread,Jan 28, 2019, 9:20:53 PM1/28/19Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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?