ansible ucs intersight error

any idea why I keep getting this error with this pb?

dictionary list is

uuid_pools:

  • name_of_uuid_pool: “UUID Pool 1”
    uuid_prefix: “00000000-0000-0000”
    uuid_size: 100
    uuid_from: “0000-000000000001”

  • name_of_uuid_pool: “UUID Pool 2”
    uuid_prefix: “11111111-1111-1111”
    uuid_size: 50
    uuid_from: “1111-111111111101”

It says malformed json, so that’s pretty obvious.
Try running with -v to (hopefully) see what’s being posted as json and there should be your solution.

The full traceback is:
File “/var/folders/_f/psbm0b654t9c729qy7r_xl240000gn/T/ansible_cisco.intersight.intersight_rest_api_payload_zqzy7erf/ansible_cisco.intersight.intersight_rest_api_payload.zip/ansible_collections/cisco/intersight/plugins/module_utils/intersight.py”, line 243, in call_api
raise RuntimeError(info[‘status’], info[‘msg’], info[‘body’])
failed: [localhost] (item={‘name_of_uuid_pool’: ‘UUID Pool 1’, ‘uuid_prefix’: ‘00000000-0000-0000’, ‘uuid_size’: 100, ‘uuid_from’: ‘0000-000000000001’}) => {
“ansible_loop_var”: “item”,
“changed”: false,
“invocation”: {
“module_args”: {
“api_body”: {
“AssignmentOrder”: “default”,
“Description”: “UUID Pool 1”,
“Name”: “UUID Pool 1”,
“Organization”: {
“Moid”: “64fb3cc06972653301785b28”
},
“Prefix”: “00000000-0000-0000”,
“Tags”: [
{
“Key”: “configmode”,
“Value”: “ansible”
},
{
“Key”: “prefix”,
“Value”: “PKXXXPK”
}
],
“UuidSuffixBlocks”: [
{
“From”: “0000-000000000001”,
“Size”: “100”
}
]
},
“api_key_id”: “64fb3cbd7564613301d27632/64fb3cbe7564613301d27636/64fe94c77564613301f091c2”,
“api_private_key”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,
“api_uri”: “https://intersight.com/api/v1”,
“list_body”: null,
“query_params”: {
“$filter”: “Name eq ‘UUID Pool 1’”
},
“resource_path”: “/uuidpool/Pools”,
“return_list”: false,
“state”: “present”,
“update_method”: “patch”,
“use_proxy”: true,
“validate_certs”: true
}
},
“item”: {
“name_of_uuid_pool”: “UUID Pool 1”,
“uuid_from”: “0000-000000000001”,
“uuid_prefix”: “00000000-0000-0000”,
“uuid_size”: 100
},
“msg”: "API error: (400, ‘HTTP Error 400: Bad Request’, b’{"code":"InvalidRequest","message":"Cannot execute the request. The JSON document is malformed.","messageId":"barcelona_request_malformed_json","traceId":"2wMlVD0eKFBFiksN2fyS47UyPFHNB4WiXSwqP_pg8FP7QZ-s81Tb1A==","cause":{"code":"InternalServerError","message":"Cannot execute the request due to an error. Retry later.","messageId":"barcelona_request_internal_error","traceId":"2wMlVD0eKFBFiksN2fyS47UyPFHNB4WiXSwqP_pg8FP7QZ-s81Tb1A=="}}') "
}

The dictionary loop is not working. But when I specify the parameters not in a dictionary and not in a loop it works.

Run that with -v, and then compare the invocation dict with the one above that fails.

TASK [create_pools : Create UUID Pool] **************************************************************
failed: [localhost] (item={‘name_of_uuid_pool’: ‘UUID Pool 1’, ‘uuid_prefix’: ‘00000000-0000-0000’, ‘uuid_size’: 100, ‘uuid_from’: ‘0000-000000000001’}) => {“ansible_loop_var”: “item”, “changed”: false, “item”: {“name_of_uuid_pool”: “UUID Pool 1”, “uuid_from”: “0000-000000000001”, “uuid_prefix”: “00000000-0000-0000”, “uuid_size”: 100}, “msg”: "API error: (400, ‘HTTP Error 400: Bad Request’, b’{"code":"InvalidRequest","message":"Cannot execute the request. The JSON document is malformed.","messageId":"barcelona_request_malformed_json","traceId":"3W5INgQdjpSiG4-JcJ4GUxrlpnuU7Ksyjj2zDfhbucx5_enmAf2wHw==","cause":{"code":"InternalServerError","message":"Cannot execute the request due to an error. Retry later.","messageId":"barcelona_request_internal_error","traceId":"3W5INgQdjpSiG4-JcJ4GUxrlpnuU7Ksyjj2zDfhbucx5_enmAf2wHw=="}}‘) "}
failed: [localhost] (item={‘name_of_uuid_pool’: ‘UUID Pool 2’, ‘uuid_prefix’: ‘11111111-1111-1111’, ‘uuid_size’: 50, ‘uuid_from’: ‘1111-111111111101’}) => {“ansible_loop_var”: “item”, “changed”: false, “item”: {“name_of_uuid_pool”: “UUID Pool 2”, “uuid_from”: “1111-111111111101”, “uuid_prefix”: “11111111-1111-1111”, “uuid_size”: 50}, “msg”: "API error: (400, ‘HTTP Error 400: Bad Request’, b’{"code":"InvalidRequest","message":"Cannot execute the request. The JSON document is malformed.","messageId":"barcelona_request_malformed_json","traceId":"VZYagTdrbBl92Gj4ePwQdT1-Ttwce57ZJYiCdkZ0bmz1CFpzsJ1h-A==","cause":{"code":"InternalServerError","message":"Cannot execute the request due to an error. Retry later.","messageId":"barcelona_request_internal_error","traceId":"VZYagTdrbBl92Gj4ePwQdT1-Ttwce57ZJYiCdkZ0bmz1CFpzsJ1h-A=="}}') "}

PLAY RECAP ******************************************************************************************
localhost : ok=10 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

This looks like another failed attempt.
Compare a failed attempt with a successful attempt using -v and look closely at the payload.

this is from the successful attempt without loop

TASK [create_pools : Create UUID Pool1] *************************************************************
ok: [localhost] => {“api_response”: {“AccountMoid”: “64fb3cbd7564613301d27632”, “Ancestors”: , “Assigned”: 0, “AssignmentOrder”: “default”, “BlockHeads”: [{“ClassId”: “mo.MoRef”, “Moid”: “65036e7069627531010b73cc”, “ObjectType”: “uuidpool.Block”, “link”: “https://www.intersight.com/api/v1/uuidpool/Blocks/65036e7069627531010b73cc”}], “ClassId”: “uuidpool.Pool”, “CreateTime”: “2023-09-14T20:34:56.056Z”, “Description”: “UUID_default_01”, “DomainGroupMoid”: “64fb3cbd7564613301d27633”, “ModTime”: “2023-09-14T20:34:56.064Z”, “Moid”: “65036e7069627531010b73c9”, “Name”: “UUID_default_01”, “ObjectType”: “uuidpool.Pool”, “Organization”: {“ClassId”: “mo.MoRef”, “Moid”: “64fb3cc06972653301785b28”, “ObjectType”: “organization.Organization”, “link”: “https://www.intersight.com/api/v1/organization/Organizations/64fb3cc06972653301785b28”}, “Owners”: [“64fb3cbd7564613301d27632”], “PermissionResources”: [{“ClassId”: “mo.MoRef”, “Moid”: “64fb3cc06972653301785b28”, “ObjectType”: “organization.Organization”, “link”: “https://www.intersight.com/api/v1/organization/Organizations/64fb3cc06972653301785b28”}], “Prefix”: “00000000-0000-0000”, “Reservations”: , “Reserved”: 0, “SharedScope”: “”, “Size”: 100, “Tags”: [{“Key”: “configmode”, “Value”: “ansible”}, {“Key”: “prefix”, “Value”: “PKXXXPK”}], “UuidSuffixBlocks”: [{“ClassId”: “uuidpool.UuidBlock”, “From”: “0000-000000000001”, “ObjectType”: “uuidpool.UuidBlock”, “Size”: 100, “To”: “0000-000000000064”}]}, “changed”: false, “trace_id”: “Cvz_QEUlWzAC1sIt_gToSQMndG0T9FtgfA7_j4r87Gdy62jJzp_eTQ==”}

TASK [create_pools : Create UUID Pool2] *************************************************************
ok: [localhost] => {“api_response”: {“AccountMoid”: “64fb3cbd7564613301d27632”, “Ancestors”: , “Assigned”: 0, “AssignmentOrder”: “default”, “BlockHeads”: [{“ClassId”: “mo.MoRef”, “Moid”: “65036e7169627531010b73d2”, “ObjectType”: “uuidpool.Block”, “link”: “https://www.intersight.com/api/v1/uuidpool/Blocks/65036e7169627531010b73d2”}], “ClassId”: “uuidpool.Pool”, “CreateTime”: “2023-09-14T20:34:57.18Z”, “Description”: “liprd-uuid-pool”, “DomainGroupMoid”: “64fb3cbd7564613301d27633”, “ModTime”: “2023-09-14T20:34:57.187Z”, “Moid”: “65036e7169627531010b73cf”, “Name”: “liprd-uuid-pool”, “ObjectType”: “uuidpool.Pool”, “Organization”: {“ClassId”: “mo.MoRef”, “Moid”: “64fb3cc06972653301785b28”, “ObjectType”: “organization.Organization”, “link”: “https://www.intersight.com/api/v1/organization/Organizations/64fb3cc06972653301785b28”}, “Owners”: [“64fb3cbd7564613301d27632”], “PermissionResources”: [{“ClassId”: “mo.MoRef”, “Moid”: “64fb3cc06972653301785b28”, “ObjectType”: “organization.Organization”, “link”: “https://www.intersight.com/api/v1/organization/Organizations/64fb3cc06972653301785b28”}], “Prefix”: “00000000-3000-0000”, “Reservations”: , “Reserved”: 0, “SharedScope”: “”, “Size”: 20, “Tags”: [{“Key”: “configmode”, “Value”: “ansible”}, {“Key”: “prefix”, “Value”: “PKXXXPK”}], “UuidSuffixBlocks”: [{“ClassId”: “uuidpool.UuidBlock”, “From”: “0000-000000000001”, “ObjectType”: “uuidpool.UuidBlock”, “Size”: 20, “To”: “0000-000000000014”}]}, “changed”: false, “trace_id”: “3QF47O7jzsQWGHSx5Loo0HE-KXuV5G9G_gj2WzdUGSmPAOCYJBrxTg==”}

added debug to the loop

The full traceback is:
File “/var/folders/_f/psbm0b654t9c729qy7r_xl240000gn/T/ansible_cisco.intersight.intersight_rest_api_payload_dxt4y__0/ansible_cisco.intersight.intersight_rest_api_payload.zip/ansible_collections/cisco/intersight/plugins/module_utils/intersight.py”, line 243, in call_api
raise RuntimeError(info[‘status’], info[‘msg’], info[‘body’])
failed: [localhost] (item={‘name_of_uuid_pool’: ‘UUID Pool 1’, ‘uuid_prefix’: ‘00000000-0000-0000’, ‘uuid_size’: 100, ‘uuid_from’: ‘0000-000000000001’}) => {
“ansible_loop_var”: “item”,
“changed”: false,
“invocation”: {
“module_args”: {
“api_body”: {
“AssignmentOrder”: “default”,
“Description”: “UUID Pool 1”,
“Name”: “UUID Pool 1”,
“Organization”: {
“Moid”: “64fb3cc06972653301785b28”
},
“Prefix”: “00000000-0000-0000”,
“Tags”: [
{
“Key”: “configmode”,
“Value”: “ansible”
},
{
“Key”: “prefix”,
“Value”: “PKXXXPK”
}
],
“UuidSuffixBlocks”: [
{
“From”: “0000-000000000001”,
“Size”: “100”
}
]
},
“api_key_id”: “64fb3cbd7564613301d27632/64fb3cbe7564613301d27636/64fe94c77564613301f091c2”,
“api_private_key”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,
“api_uri”: “https://intersight.com/api/v1”,
“list_body”: null,
“query_params”: {
“$filter”: “Name eq ‘UUID Pool 1’”
},
“resource_path”: “/uuidpool/Pools”,
“return_list”: false,
“state”: “present”,
“update_method”: “patch”,
“use_proxy”: true,
“validate_certs”: true
}
},
“item”: {
“name_of_uuid_pool”: “UUID Pool 1”,
“uuid_from”: “0000-000000000001”,
“uuid_prefix”: “00000000-0000-0000”,
“uuid_size”: 100
},
“msg”: "API error: (400, ‘HTTP Error 400: Bad Request’, b’{"code":"InvalidRequest","message":"Cannot execute the request. The JSON document is malformed.","messageId":"barcelona_request_malformed_json","traceId":"ur4PRfwWJ10NUyohmov0beVOPV4DCu_Mkab1JyqRHBL371h-FJKcEQ==","cause":{"code":"InternalServerError","message":"Cannot execute the request due to an error. Retry later.","messageId":"barcelona_request_internal_error","traceId":"ur4PRfwWJ10NUyohmov0beVOPV4DCu_Mkab1JyqRHBL371h-FJKcEQ=="}}') "

This is again a failed attempt…

To summarise, a task is failing with an error about malformed JSON, if you run it in a loop. And it succeeds without a loop.
So, if you run both of them using -v, this will allow you to compare their invocation (to be precise, the api_body key).

You should compare that value between the failed and successful run.

i already posted this without the loop: please see below. I am not sure why the loop is not working.

this is from the successful attempt without loop

TASK [create_pools : Create UUID Pool1] *************************************************************
ok: [localhost] => {“api_response”: {“AccountMoid”: “64fb3cbd7564613301d27632”, “Ancestors”: , “Assigned”: 0, “AssignmentOrder”: “default”, “BlockHeads”: [{“ClassId”: “mo.MoRef”, “Moid”: “65036e7069627531010b73cc”, “ObjectType”: “uuidpool.Block”, “link”: “https://www.intersight.com/api/v1/uuidpool/Blocks/65036e7069627531010b73cc”}], “ClassId”: “uuidpool.Pool”, “CreateTime”: “2023-09-14T20:34:56.056Z”, “Description”: “UUID_default_01”, “DomainGroupMoid”: “64fb3cbd7564613301d27633”, “ModTime”: “2023-09-14T20:34:56.064Z”, “Moid”: “65036e7069627531010b73c9”, “Name”: “UUID_default_01”, “ObjectType”: “uuidpool.Pool”, “Organization”: {“ClassId”: “mo.MoRef”, “Moid”: “64fb3cc06972653301785b28”, “ObjectType”: “organization.Organization”, “link”: “https://www.intersight.com/api/v1/organization/Organizations/64fb3cc06972653301785b28”}, “Owners”: [“64fb3cbd7564613301d27632”], “PermissionResources”: [{“ClassId”: “mo.MoRef”, “Moid”: “64fb3cc06972653301785b28”, “ObjectType”: “organization.Organization”, “link”: “https://www.intersight.com/api/v1/organization/Organizations/64fb3cc06972653301785b28”}], “Prefix”: “00000000-0000-0000”, “Reservations”: , “Reserved”: 0, “SharedScope”: “”, “Size”: 100, “Tags”: [{“Key”: “configmode”, “Value”: “ansible”}, {“Key”: “prefix”, “Value”: “PKXXXPK”}], “UuidSuffixBlocks”: [{“ClassId”: “uuidpool.UuidBlock”, “From”: “0000-000000000001”, “ObjectType”: “uuidpool.UuidBlock”, “Size”: 100, “To”: “0000-000000000064”}]}, “changed”: false, “trace_id”: “Cvz_QEUlWzAC1sIt_gToSQMndG0T9FtgfA7_j4r87Gdy62jJzp_eTQ==”}

TASK [create_pools : Create UUID Pool2] *************************************************************
ok: [localhost] => {“api_response”: {“AccountMoid”: “64fb3cbd7564613301d27632”, “Ancestors”: , “Assigned”: 0, “AssignmentOrder”: “default”, “BlockHeads”: [{“ClassId”: “mo.MoRef”, “Moid”: “65036e7169627531010b73d2”, “ObjectType”: “uuidpool.Block”, “link”: “https://www.intersight.com/api/v1/uuidpool/Blocks/65036e7169627531010b73d2”}], “ClassId”: “uuidpool.Pool”, “CreateTime”: “2023-09-14T20:34:57.18Z”, “Description”: “liprd-uuid-pool”, “DomainGroupMoid”: “64fb3cbd7564613301d27633”, “ModTime”: “2023-09-14T20:34:57.187Z”, “Moid”: “65036e7169627531010b73cf”, “Name”: “liprd-uuid-pool”, “ObjectType”: “uuidpool.Pool”, “Organization”: {“ClassId”: “mo.MoRef”, “Moid”: “64fb3cc06972653301785b28”, “ObjectType”: “organization.Organization”, “link”: “https://www.intersight.com/api/v1/organization/Organizations/64fb3cc06972653301785b28”}, “Owners”: [“64fb3cbd7564613301d27632”], “PermissionResources”: [{“ClassId”: “mo.MoRef”, “Moid”: “64fb3cc06972653301785b28”, “ObjectType”: “organization.Organization”, “link”: “https://www.intersight.com/api/v1/organization/Organizations/64fb3cc06972653301785b28”}], “Prefix”: “00000000-3000-0000”, “Reservations”: , “Reserved”: 0, “SharedScope”: “”, “Size”: 20, “Tags”: [{“Key”: “configmode”, “Value”: “ansible”}, {“Key”: “prefix”, “Value”: “PKXXXPK”}], “UuidSuffixBlocks”: [{“ClassId”: “uuidpool.UuidBlock”, “From”: “0000-000000000001”, “ObjectType”: “uuidpool.UuidBlock”, “Size”: 20, “To”: “0000-000000000014”}]}, “changed”: false, “trace_id”: “3QF47O7jzsQWGHSx5Loo0HE-KXuV5G9G_gj2WzdUGSmPAOCYJBrxTg==”}

Try with -vv or with -vvv until you see the invocation structure