我尝试将sonarqube API与ansible脚本一起使用。这就是我得到的:
---
- hosts: TestClient
vars:
sonar_url: **************
roles:
- Sonar
我的声纳角色:
- name: test task2
uri:
url: https://admin:admin@{{ sonar_url }}/api/users/change_password
method: POST
body: "{{ lookup('file', 'Authenticate.json') | from_json }} "
body_format: json
headers:
Accept: "application/json"
return_content: yes
force_basic_auth: yes
status_code: 204
validate_certs: no
还有我的JSON文件:
{
"login": "admin",
"password": "admin",
"previousPassword": "admin"
}
JSON文件位于同一目录中,并且可以读取。如果现在执行脚本,则会收到错误:
完整的回溯是:
fatal: [*************]: FAILED! => { "changed": false, "connection": "close", "content": "{\"errors\":[{\"msg\":\"The 'login' parameter is missing\"}]}", "content_length": "55", "content_type": "application/json", "date": "Fri, 08 Feb 2019 10:22:14 GMT", "invocation": { "module_args": { "attributes": null, "backup": null, "body": { "login": "admin", "password": "admin", "prevopusPassword": "admin" }, "body_format": "json", "client_cert": null, "client_key": null, "content": null, "creates": null, "delimiter": null, "dest": null, "directory_mode": null, "follow": false, "follow_redirects": "safe", "force": false, "force_basic_auth": true, "group": null, "headers": { "Accept": "application/json", "Authorization": "Basic *********=", "Content-Type": "application/json" }, "http_agent": "ansible-httpget", "method": "POST", "mode": null, "owner": null, "regexp": null, "remote_src": null, "removes": null, "return_content": true, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "status_code": [ "204" ], "timeout": 30, "unsafe_writes": null, "url": "https://*********/api/users/change_password", "url_password": null, "url_username": null, "use_proxy": true, "validate_certs": false } }, "json": { "errors": [ { "msg": "The 'login' parameter is missing" } ] },
`
据我所知,如上所述,可以读取JSON文件,但无法正确转换,因此POST请求实际上可以获取此信息。
我的问题是: JSON文件中是否缺少配置选项或其他内容?
感谢您的时间和帮助。