0
我试图调用一些REST API并对Ansible服务执行一些POST请求。由于正文(JSON)发生变化,我正在尝试对某些文件执行循环。这里是剧本:Ansible:循环文件做POST请求
- hosts: 127.0.0.1
any_errors_fatal: true
tasks:
- name: do post requests
uri:
url: "https://XXXX.com"
method: POST
return_content: yes
body_format: json
headers:
Content-Type: "application/json"
X-Auth-Token: "XXXXXX"
body: "{{ lookup('file', "{{ item }}") }}"
with_file:
- server1.json
- server2.json
- proxy.json
但是当我运行的剧本,我得到这个错误:
the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'item' is undefined
问题出在哪里?
另外一个问题。你提供的解决方案工作正常,但现在我得到这个错误:无法找到(...内容的server1.json ...)在预期的路径。 json文件位于剧本的相同目录中,这里会出现什么问题? – SegFault
查看更新的答案。 – techraf
谢谢。现在更清楚了。 – SegFault