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