cloudera-labs / cloudera.cluster

An Ansible collection for lifecycle and management of Cloudera CDP Private Cloud resources on bare metal, IaaS, and PaaS.
Apache License 2.0
32 stars 46 forks source link

roles/deployment/cluster/tasks/create_data_context.yml failed_when condition not correct #173

Open hadoopch opened 6 months ago

hadoopch commented 6 months ago

Hi,

in create_data_context.yml the failed_when condition seems to be not correct

---

- name: Create data contexts
  cloudera.cluster.cm_api:
    endpoint: /dataContexts
    method: POST
    body: "{{ lookup('template', 'sdx/data_context.j2', convert_data=False) }}"
  loop: "{{ cluster.data_contexts }}"
  loop_control:
    loop_var: data_context
  register: result
  failed_when:
    - result.status != 200
    - "'already exists' not in result.json.message | default('')"
  when:
    - cluster.data_contexts is iterable
    - "'HDFS' in cluster.services"

I get the following error if i run the cluster.yml playbook a second time

TASK [cloudera.cluster.cluster : Create data contexts] *******************************************************************************************************************************************************************************************************
failed: [cm001.cdp.lan] (item={'name': 'SDX', 'services': ['HDFS', 'HIVE', 'ATLAS', 'RANGER', 'OZONE']}) => {"ansible_loop_var": "data_context", "cache_control": "no-cache, no-store, max-age=0, must-revalidate", "changed": false, "connection": "close", "content": "{\n  \"message\" : \"Data Context with the name SDX already exists\"\n}", "content_type": "application/json;charset=utf-8", "data_context": {"name": "SDX", "services": ["HDFS", "HIVE", "ATLAS", "RANGER", "OZONE"]}, "date": "Thu, 14 Dec 2023 12:40:11 GMT", "elapsed": 0, "expires": "0", "failed_when_result": true, "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request", "pragma": "no-cache", "redirected": false, "set_cookie": "SESSION=ZTQ5NjUwYmMtZjY4MC00M2YzLTllNWUtMWZhNjkyOGNlOWJi; Path=/; Secure; HttpOnly; SameSite=Lax", "status": 400, "strict_transport_security": "max-age=31536000 ; includeSubDomains", "url": "https://cm001.cdp.lan:7183/api/v54/dataContexts", "x_content_type_options": "nosniff", "x_frame_options": "DENY", "x_xss_protection": "1; mode=block"}

Because of the loop everything is put into result.results array.


- debug:
    msg:
     - "result is {{result.results[0].status}}"
     - "message is {{result.results[0].content}}"

ok: [cm001.cdp.lan] => {
    "msg": [
        "result is 400",
        "message is {\n  \"message\" : \"Data Context with the name SDX already exists\"\n}"
    ]
}

Regards

Uli

wmudge commented 6 months ago

Thanks for submitting this issue. The failed_when does look off.

In the (hopefully near) future, this entire task and function will be consumed into a single module. Something like cloudera.cluster.cm_data_context and looping with that module.