I try to communicate with zabbix API with ansible. It waits for a json input and process it, however, it does not work. My playbook task looks like this:
- name: Login to zabbix
uri:
url: https://{{ zabbix_server_ip }}/api_jsonrpc.php
method: POST
validate_certs: false
body:
jsonrpc: 2.0
method: user.login
params:
user: admin
password: XXX
id: 1
auth: null
body_format: json
register: zabbix_login
If I run the playbook with -vvvv
then I see what was posted to the API by ansible. The interesting part looks like this:
"body": {
"auth": null,
"id": 1,
"jsonrpc": 2.0,
"method": "user.login",
"params": {
"password": "XXX",
"user": "admin"
}
Which is correct, the same should be posted, but zabbix_login
remains empty from the API answer, because of this error message (also parsed from -vvvv
):
"json": {
"error": {
"code": -32600,
"data": "Invalid parameter \"/jsonrpc\": a character string is expected.",
"message": "Invalid Request."
},
"id": 1,
"jsonrpc": "2.0"
},
I belive the problem should be that the API wants jsonrpc: 2.0
parameter at the beginning of the request, as it's documentation described it. But it seems ansible reordering the json request somehow to alphabetical order. How do I prevent this?
I already read this question: How to prevent Ansible from re-ordering JSON? and also the answer, but it just reorders the answer for the request. I need to keep the same order of the request, as wrote in the playbook.