如何使用json格式的答案与get_url模块的URL?

问题描述 投票:0回答:2

我正在请求REST API为我提供特定项目的下载URL(这是由uri模块解决的)。然后我尝试在get_url模块中使用url,但它失败并显示以下消息

FAILED! => {"msg": "template error while templating string: expected name or number. String: {{ cora_response.json.['@odata.mediaReadLink'].stdout | from_json }}"}

我怎么想把变量放到url参数中?我的任务看起来像这样:

- name: Download Link from REST
   debug: var=cora_response.json['@odata.mediaReadLink']

- name: Download the latest Release
  get_url:
    url: "{{ cora_response.json.['@odata.mediaReadLink'].stdout | from_json }}"
    dest: "{{ installation_path }}/install/19.3.zip"
    mode: 660

我的调试任务向我显示了我尝试使用的URL,但是get_url模块失败了。

请提前告知并提前感谢。

编辑:尝试@ al76建议的以下内容

- name: Download the latest CH Release
  get_url:
    url: "{{ cora_response.json['@odata.mediaReadLink'].stdout | from_json }}"
    dest: "{{ installation_path }}/install/CH19.3.zip"
    mode: 660

错误信息:

fatal: [ln-lnxcelcon01.owo.company]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ cora_response.json['@odata.mediaReadLink'].stdout | from_json }}): expected string or buffer"}
json rest ansible
2个回答
0
投票

尝试

url: "{{ cora_response.json['@odata.mediaReadLink'].stdout | from_json }}"

0
投票

盲目的运气让我摆脱了痛苦

url: "{{ cora_response.json['@odata.mediaReadLink'] }}"
© www.soinside.com 2019 - 2024. All rights reserved.