I have Ansible output from a task which is registered to task_output
.
"ansible_loop_var": "item",
"changed": false,
"files": [
{
"path": "file/path",
}
I tried to captured the path but none of there are working
"{{ task_output.files | map(attribute='path') }}"
"{{ task_output[0].files[0] | map(attribute='path') }}"
"{{ task_output[0].files | map(attribute='path') }}"
"{{ task_output.files[0] | map(attribute='path') }}"
"{{ task_output.json.files | map(attribute='path') }}"
"{{ task_output | map(attribute='path') }}"
I have Ansible output from a task which is registered to task_output
.
"ansible_loop_var": "item",
"changed": false,
"files": [
{
"path": "file/path",
}
I tried to captured the path but none of there are working
"{{ task_output.files | map(attribute='path') }}"
"{{ task_output[0].files[0] | map(attribute='path') }}"
"{{ task_output[0].files | map(attribute='path') }}"
"{{ task_output.files[0] | map(attribute='path') }}"
"{{ task_output.json.files | map(attribute='path') }}"
"{{ task_output | map(attribute='path') }}"
Share
Improve this question
edited Jan 30 at 10:17
U880D
12.3k6 gold badges33 silver badges67 bronze badges
asked Jan 29 at 18:24
AnsirockAnsirock
11 bronze badge
3
|
1 Answer
Reset to default 0For a list with a single element a minimal example playbook
---
- hosts: localhost
become: false
gather_facts: false
vars:
files: [
{
"path": "file/path",
}
]
tasks:
- debug:
var: (files | first).path
- debug:
var: files | map(attribute='path')
will result into an output of
TASK [debug] ********************
ok: [localhost] =>
(files | first).path: file/path
TASK [debug] ********************
ok: [localhost] =>
files | map(attribute='path'):
- file/path
task_output.files[0].path
ortask_output.files.0.path
, even. – β.εηοιτ.βε Commented Jan 29 at 18:36map
, you need a list, but by getting the element0
, you don't have a list anymore, instead, you have a dictionary. – β.εηοιτ.βε Commented Jan 29 at 18:37files": [ { "path": "file/path", }
does not looks valid to me. – U880D Commented Jan 30 at 10:40