I have a file file.sub
which contains this JSON
object {"kas_sub.test1": "true", "kas_sub.test2": "true"}
. I would extract the keys
and to get this: kas_sub.test1 kas_sub.test1
.
When i try
- shell: 'cat path/to/file.sub'
register: file1
- debug:
var: file1.stdout_lines
I got:
TASK [shell] *****************************************************************************************************************
changed: [ansible4]
changed: [control]
TASK [debug] *****************************************************************************************************************
ok: [control] => {
"file1.stdout_lines": [
"{\"kas_sub.tes1\": \"true\", \"kas_sub.test2\": \"true\"}"
]
}
So it's not conserving the same JSON format
because i would use the json_query
filter.
- debug:
msg: "{{ file1.stdout_lines| json_query(value1)}}"
vars:
value1: "@[?keys(@)]"
keys(@)
function doesn't return anything
ok: [control] => {
"msg": ""
}