#body: "{{ lookup('file','{{item[\"path\"]}}') }}" 用lookup插件读取不了json文件
在playbooks的main.yml 文件写法如下
- name: "get json body"
shell: cat "{{item['path']}}"
# shell: echo 'hello'
loop: "{{json_files.files}}"
register: json_body
利用以上读到的json_body,遍历读出
- name: "check json body"
debug:
msg:
- "{{item.stdout}}"
loop: "{{json_body.results}}"
遍历读取:
- name: "Deploy with Hafal API"
uri:
url: "{{Hafal_server_IP}}/module/{{data44_model}}/HHlator/{{item.item.path.split('/')[-1].split('.')[0]}}"
method: POST
headers:
Content-Type: application/json
Accept: application/json
Authorization: "{{auth_token_rafal}}"
X-HSBC-E2E-Trust-Token: "{{auth_token_dsp}}"
body_format: json
body: "{{item.stdout}}"
with_items: "{{json_body.results}}"