Tôi muốn thực hiện một yêu cầu POST đến một endpoint API qua Ansible nơi một số mục trong bài dữ liệu là năng động, đây là những gì tôi cố gắng và thất bại:bài Json để API qua Ansible
body_content.json My :
{
apiKey: '{{ KEY_FROM_VARS }}',
data1: 'foo',
data2: 'bar'
}
Và đây là nhiệm vụ Ansible tôi:
# Create an item via API
- uri: url="http://www.myapi.com/create"
method=POST return_content=yes HEADER_Content-Type="application/json"
body="{{ lookup('file','create_body.json') | to_json }}"
Thật đáng buồn này không hoạt động:
failed: [localhost] => {"failed": true}
msg: this module requires key=value arguments
....
FATAL: all hosts have already failed -- aborting
phiên bản ansible tôi là 1.9.1
này không làm việc cho tôi. Tôi phải loại bỏ '| to_json' và thêm 'body_format: json' – dokaspar