Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hadoopch opened this issue Dec 15, 2023 · 1 comment · May be fixed by #179
Open

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

hadoopch opened this issue Dec 15, 2023 · 1 comment · May be fixed by #179
Labels
bug Something isn't working

Comments

@hadoopch
Copy link

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 wmudge added the bug Something isn't working label Dec 18, 2023
@wmudge
Copy link
Member

wmudge commented Dec 18, 2023

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.

@wmudge wmudge linked a pull request Dec 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants