首页 > 解决方案 > 无法使用 uri 模块 ansible 在 dynatrace 中创建管理区域

问题描述

我很难使用 rhel 7 上的 ansible playbook 在 dynatrace 中创建管理区域,下面是我的代码,以及预期输出和实际输出

uri:
        url: "https://{{ xxxxxxx }}/e/{{ xxxxxxx }}/api/config/v1/managementZones"
        method: POST
        return_content: yes
        validate_certs: no
        status_code: 201,400
        headers:
           Accept: 'application/json'
           Authorization: 'Api-Token {{ xxxxxxxx }}'
        body_format: json
        body: "{{ somejsonoutput }}"
      register: managzone
      run_once: true

如果上面的代码不可用但它没有按预期工作,我期待上面的代码创建管理区域。

预期输出:

dynatrace_response_source": "Cluster",
        "elapsed": 0,
        "failed": false,
        "frame_options": "xxxxxxx",
        "json": {
            id: "xxxxx"
            name: "xxxxx"
                    }
            }
        },
        "msg": "HTTP Error 400: Bad Request",
        "pragma": "no-cache",
        "redirected": false,
        "status": 400,

但以下是实际输出

输出

"dynatrace_response_source": "Cluster",
        "elapsed": 0,
        "failed": false,
        "frame_options": "xxxxxxx",
        "json": {
            "error": {
                "code": 400,
                "constraintViolations": [
                    {
                        "location": null,
                        "message": "must not be blank",
                        "parameterLocation": "PAYLOAD_BODY",
                        "path": "name"
                    }
                ],
                "message": "Constraints violated."
            }
        },
        "msg": "HTTP Error 400: Bad Request",
        "pragma": "no-cache",
        "redirected": false,
        "status": 400,

标签: ansibledynatrace

解决方案


看起来您缺少有效负载主体(json 格式)中的参数之一,或者您的 json 结构无效。在文档中检查它。
必填项之一是 MZ 的名称,其他参数是可选的。首先尝试创建没有规则的MZ。


推荐阅读