简体   繁体   中英

Ansible API Call vRealize Automation 7 catalog Item error when sending POST request

I am trying to make an API call to execute a Catalog Item in VRA 7. I am sending a JSON in the POST body request. This it the JSON

{
  "type": "com.vmware.vcac.catalog.domain.request.CatalogItemProvisioningRequest",
  "catalogItemId": "00ff80ee-ab53-0000-bd1b-3eccc000a00b",
  "requestedFor": "accountblabla@mail.ca",
  "businessGroupId": "000d418a-00b8-0000-a00d-f9d3775ad001",
  "description": null,
  "reasons": null,
  "data": {
    "_leaseDays": 1,
    "_number_of_instances": 1,
    "xa_ene_prod_NessusScanEnLot": {
      "componentTypeId": "com.vmware.csp.component.cafe.composition",
      "componentId": null,
      "classId": "Blueprint.Component.Declaration",
      "typeFilter": "xa_ene_prod_NessusScanEnLot.xa_ene_prod_NessusScanEnLot",
      "data": {
        "_declarationId": "xa_ene_prod_NessusScanEnLot",
        "_description": "",
        "_hasChildren": false,
        "cipDemandeur": "{fnessuscan_byrest_cipDemandeur}}",
        "csvReportId": "f{nessuscan_byrest_csvReportIci}l",
        "dropDown_scanTemplateId": "126",
        "hq_app": "dne"
        "serverArray": "{{serverArray}}"
      }
    }
  }
}

The content of the variable serrerArray is a set_fact of the hostname of a server like abcd706.hse.hydra.ca:

set_fact:
 serverArray: {[abcddne706]}

When I run my request with ansible Tower, everything works until the last part with the serverArray. I get this error:

"message": "The value for the field "serverArray" is not a ,MultipleLiteral but the field is  defined as Multivalued,
"code": 11011

What does that mean please? I am still new with learning Ansible and all the Map/Dictionnary/Array objects so I am not sure how to resolve this. What would be the correct way to set the content of serverArray?

Thank you

As I see you're trying to pass a wrong variable type in serverArray : "{{serverArray}}" which is just a string, but your facts contains a list inside of dict:

serverArray: {[abcddne706]}

You can test running the next ansible tasks for better understanding:

    - name: "set variable"
      set_fact:
        foo: "abcddne706"

    - name: "set wrappers for foo"
      set_fact:
        bar: "{[ {{ foo }} ]}"
        baz:
          - "{[ {{ foo }} ]}"

    - name: "Show foo variable as as string"
      debug:
        var: foo

    - name: "Show the results of foo put inside of list and wrapped by dict"
      debug:
        var: bar

    - name: "Show the results as foo put inside of list and wrapped by dict then set as list item"
      debug:
        var: baz

with the next output:

TASK [Show foo variable as as string] *********************************************************************
ok: [10.1.1.1] => {                                                 
    "foo": "abcddne706"                                                                                                                                                                                                                                                                     
}

TASK [Show the results of foo put inside of list and wrapped by dict] *********************************************************************
ok: [10.1.1.1] => {                                                 
    "bar": "{[ abcddne706 ]}"                                          
}

TASK [Show the results as foo put inside of list and wrapped by dict then set as list item] *********************************************************************
ok: [10.10.1.1] => {                                                 
    "baz": [                                                           
        "{[ abcddne706 ]}"                                             
    ]                                                                  
} 

So number two looks like your serverArray ansible fact.

You can also iterate over list items with different keys and values in ansible. Every list item is a dict with two keys and values pair:

- name: "Show some keys and values"
  debug:
    msg: >
      Here is a dict item: {{ item }}
      which consists of: item.key1 = {{ item.key1 }}; item.key2 = {{ item.key2 }}
  with_items:
    - { key1: 'value1', key2: 'value2' }
    - { key1: 'value3', key2: 'value4' }

Output:

TASK [Show some keys and values] *********************************************************************
ok: [10.1.1.1] => (item={'key1': 'value1', 'key2': 'value2'}) => {
    "msg": "Here is a dict item: {'key1': 'value1', 'key2': 'value2'} which consists of: item.key1 = value1; item.key2 = value2\n"
}
ok: [10.1.1.1] => (item={'key1': 'value3', 'key2': 'value4'}) => {
    "msg": "Here is a dict item: {'key1': 'value3', 'key2': 'value4'} which consists of: item.key1 = value3; item.key2 = value4\n"
}

Maybe it might brings some difference explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM