首页 > 解决方案 > Ansible - 补救工单自动化

问题描述

我正在尝试使用 Ansible 自动化 Remedy - Incident Management Ticket 创建。为此,我正在尝试连接到 Remedy API,但出现以下错误。

代码:

-
       name: Testing GET Method
       hosts: localhost
       tasks:

             - name: Create a Incident Ticket
               uri:
                   url: https://testapi.xyz.com/t/app.misc/remedyLogin/1.0/login
                   method: POST
                   headers:
                           "Authorization": "Bearer xxxxx-xxxxxx-xxxxxxxxx-xxxxx"
                           "Content-Type": "application/x-www-form-urlencoded"
                   body: '{"username": "some_username", "password": "some_password"}'
                   validate_certs: False
                   force_basic_auth: yes
                   return_content: yes
                   status_code: 200
                   register: result
             - debug: msg="{{ result.status }}"

更准确地说。我的补救措施需要用户名和密码以及访问令牌,为此我在标题部分添加了授权。我可能是错误的添加授权。

错误:

fatal: [localhost]: FAILED! => {
  "access_control_allow_headers": "authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction", 
  "access_control_allow_methods": "POST", 
  "access_control_allow_origin": "*", 
  "cache_control": "must-revalidate,no-cache,no-store", 
  "changed": false, 
  "connection": "close", 
  "content": "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\"/>\n<title>Error 500 </title>\n</head>\n<body>\n<h2>HTTP ERROR: 500</h2>\n<p>Problem accessing /api/jwt/login. Reason:\n<pre>    Request failed.</pre></p>\n<hr />\n</body>\n</html>\n", 
  "content_security_policy": "frame-ancestors 'self'", 
  "content_type": "text/html;charset=iso-8859-1", 
  "date": "Tue, 14 Apr 2020 11:17:07 GMT", 
  "msg": "Status code was 500 and not [200]: HTTP Error 500: Request failed.", 
  "redirected": false, 
  "status": 500, 
  "transfer_encoding": "chunked", 
  "url": "https://testapi.xyz.com/t/app.misc/remedyLogin/1.0/login", 
  "x_frame_options": "SAMEORIGIN"
}

请帮助我。

标签: ansibleremedy

解决方案


您需要将 body_format 参数添加到 uri 模块示例:

         - name: Create a Incident Ticket
           uri:
               url: https://testapi.xyz.com/t/app.misc/remedyLogin/1.0/login
               method: POST
               headers:
                       "Authorization": "Bearer xxxxx-xxxxxx-xxxxxxxxx-xxxxx"
                       "Content-Type": "application/x-www-form-urlencoded"
               body: '{"username": "some_username", "password": "some_password"}'
               body_format: form-urlencoded
               validate_certs: False
               force_basic_auth: yes
               return_content: yes
               status_code: 200
               register: result

推荐阅读