Skip to content

[Bug] ntnx_categories_v2 is not idempotent #890

@rfults

Description

@rfults

The following task fails when the category or values exist:

- name: Create category key & value v2
  nutanix.ncp.ntnx_categories_v2:
    nutanix_host: "{{ nutanix_pc_hostname }}"
    nutanix_username: "{{ nutanix_username }}"
    nutanix_password: "{{ nutanix_password }}"
    validate_certs: false
    key: "{{ item.key }}"
    value: "{{ item.value }}"
  loop: "{{ ntnx_categories }}"

Expected behavior
Expect the module to return unchanged if the category and value combination exists.

Additional context
The full traceback is:
File "/tmp/ansible_nutanix.ncp.ntnx_categories_v2_payload_dwbpyb92/ansible_nutanix.ncp.ntnx_categories_v2_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_categories_v2.py", line 230, in create_category
resp = categories.create_category(body=spec)
File "/usr/local/lib/python3.13/site-packages/ntnx_prism_py_client/api/categories_api.py", line 134, in create_category
(data) = self.api_client._call_api(
'/api/prism/v4.2/config/categories', 'POST',
...<11 lines>...
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
File "/usr/local/lib/python3.13/site-packages/ntnx_prism_py_client/api_client.py", line 843, in _call_api
return self.__call_api(resource_path, method,
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
path_params, query_params, header_params,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
_return_http_data_only, collection_formats,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_preload_content, _request_timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/ntnx_prism_py_client/api_client.py", line 598, in __call_api
response_data = self.request(
method, url, query_params=query_params, headers=header_params,
post_params=post_params, body=body,
_preload_content=_preload_content,
_request_timeout=_request_timeout)
File "/usr/local/lib/python3.13/site-packages/ntnx_prism_py_client/api_client.py", line 888, in request
return self.rest_client.POST(url,
~~~~~~~~~~~~~~~~~~~~~^^^^^
query_params=query_params,
^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
_request_timeout=client_request_timeout,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
body=body)
^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/ntnx_prism_py_client/rest.py", line 363, in POST
return self.request("POST", url,
~~~~~~~~~~~~^^^^^^^^^^^^^
headers=headers,
^^^^^^^^^^^^^^^^
...<3 lines>...
_request_timeout=_request_timeout,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
body=body)
^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/ntnx_prism_py_client/rest.py", line 322, in request
raise ApiException(http_resp=r)
failed: [localhost] (item={'key': 'CORP-Apps', 'value': 'app1'}) => {
"ansible_loop_var": "item",
"changed": false,
"error": "BAD REQUEST",
"invocation": {
"module_args": {
"key": "CORP-Apps",
"nutanix_debug": false,
"nutanix_host": "testpc1",
"nutanix_log_file": "/tmp/nutanix_ansible_debug.log",
"nutanix_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"nutanix_port": "9440",
"nutanix_username": "admin",
"state": "present",
"type": "USER",
"validate_certs": false,
"value": "app1",
"wait": true
}
},
"item": {
"key": "CORP-Apps",
"value": "app1"
},
"msg": "Api Exception raised while creating category",
"response": {
"$dataItemDiscriminator": "prism.v4.error.ErrorResponse",
"data": {
"$errorItemDiscriminator": "List<prism.v4.error.AppMessage>",
"$objectType": "prism.v4.error.ErrorResponse",
"error": [
{
"$objectType": "prism.v4.error.AppMessage",
"code": "CTGRS-50023",
"errorGroup": null,
"locale": "en-US",
"message": "Operation failed as a category with the provided key and value already exists with extId:295cb716-e5b2-32ef-b27e-ccbd7290c75a",
"severity": "ERROR"
}
]
}
},
"status": 400
}

Metadata

Metadata

Labels

bugSomething isn't workingv2.5.0

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions