可言:将JSON数据解析为变量

问题描述 投票:0回答:1
我从注册到

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
dictionary variables filter ansible jinja2
1个回答
0
投票
--- - 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

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.