ansible - Ansible URI API (JSON-RPC)
问题描述
我对 ansible 的 URI 模块有疑问,也许有人知道问题可能是什么?
我尝试使用 ansible uri 模块与 I-Doit API (JSON-RPC) 进行通信。无论我尝试手动运行 curl 还是使用 ansible,我第一次尝试 curl 都可以正常工作。
# curl manual example
curl --location --request POST 'https://SERVER-FQDN/i-doit/src/jsonrpc.php' \
--header 'Content-Type: application/json' \
--header 'X-RPC-Auth-Session: SESSION-KEY' \
--header 'Cookie: PHPSESSID=SESSION-KEY' \
--data-raw '{
"version": "2.0",
"method": "idoit.version",
"params": {
"apikey": "API-KEY",
"language": "en"
},
"id": 1
}'
# example in ansible
---
- name: CURL REST / JSON-RPC API Call
shell: |
curl -s --noproxy "*" --location --request POST 'https://SERVER-FQDN/i-doit/src/jsonrpc.php' \
--header "Content-Type: application/json" \
--header "X-RPC-Auth-Session: {{ session_key }}" \
--header "Cookie: PHPSESSID= {{ session_key }}" \
--data-raw '{
"version": "2.0",
"method": "idoit.version",
"params": {
"apikey": "{{ api_key }}",
"language": "en"
},
"id": 1
}'
如果我尝试使用 URI 模块重现调用,例如
- name: REST / JSON-RPC API Call check I-Doit Version
uri:
url: "https://SERVER-FQDN/i-doit/src/jsonrpc.php"
method: post
validate_certs: no
follow_redirects: all
use_proxy: no
timeout: 200
headers:
X-RPC-Auth-Session: "{{ SESSION-KEY }}"
Content-Type: "application/json"
body_format: json
return_content: yes
body: "{{ lookup('file','test.json') }}"
ignore_errors: yes
# test.json content
{
"version": "2.0",
"method": "idoit.version",
"params": {
"apikey": "API-KEY",
"language": "en"
},
"id": 1
}
请求失败,错误代码 -1 和消息:“连接失败:在收到有效响应之前连接已关闭:未收到状态行 - 服务器已关闭连接”
URI 模块与 rest 或 json-rpc 的使用有区别吗?
感谢您的帮助或想法
丹特加布里埃尔
解决方案
推荐阅读
- c++ - 将 1 居中放在顶部
- angular - 如何在 Angular 7 中使用 iframe
- python - Python 列表约定列表
- python - 崇高的文字3(不响应)
- php - 错误:消息:在 null 上调用成员函数 rekod()
- html - 高度为 100% 的 Div 溢出到其父级下方的 flexbox 行
- sql-server - 在 Azure SQL DB 中提取哈希用户密码
- json - 无法在 JenkinsFile 中按键读取 Json 值
- android - 构建 R8 失败 -> 错误:`dalvik.annotation.EnclosureClass` 类型的多个注释
- c++ - 如何修复 C++ 中的“arrStud 未在此范围内声明”错误