task_output
的任务中有一定的输出。
"ansible_loop_var": "item",
"changed": false,
"files": [
{
"path": "file/path",
}
我试图捕获这条路,但没有任何工作
"{{ 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') }}"
对于带有单个元素的列表,一个最小示例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')
将导致输出
TASK [debug] ********************
ok: [localhost] =>
(files | first).path: file/path
TASK [debug] ********************
ok: [localhost] =>
files | map(attribute='path'):
- file/path