uri body call needs [] instead of {}

41 views
Skip to first unread message

Nicholas Britton

unread,
Dec 13, 2019, 4:09:07 PM12/13/19
to Ansible Project
I am working on some uri calls with netbackup and with swagger shows that it only works with [] but the uri modual is using {}.   Any thoughts or tricks to get that to format correctly?


For example i am sending a body uri body of:

  - name: Create MSDP Disk Pool
    uri:
      url: "{{baseurl}}storage/disk-pools"
      method: POST
      body_format: json
      status_code: 201
      headers:
        authorization: "{{login.json.token}}"
        content-type: application/vnd.netbackup+json;version=3.0
      body:
        data:
          type: diskPool
          attributes:
            name: server_dpm
            diskVolumes:
              [name: PureDiskVolume]
            maximumIoStreams:
              limitIoStreams: true
              streamsPerVolume: 75
          relationships:
            storageServers:
              data:
                type: storageServer
                id: 'PureDisk:server.domain'
      validate_certs: no
      return_content: yes
    register: dp_create


Which produces this:

            "body": {
                "data": {
                    "attributes": {
                        "diskVolumes": [
                            {
                                "name": "PureDiskVolume"
                            }
                        ],
                        "maximumIoStreams": {
                            "limitIoStreams": true,
                            "streamsPerVolume": 75
                        },
                        "name": "server_dpm"
                    },
                    "relationships": {
                        "storageServers": {
                            "data": {
                                "id": "PureDisk:server.domain",
                                "type": "storageServer"
                            }
                        }
                    },
                    "type": "diskPool"
                }
            },



While swagger produces it as this:

working:


{
  "data": {
    "type": "diskPool",
    "attributes": {
      "name": "server_dpm",
      "diskVolumes": [
        {
          "name": "PureDiskVolume"
        }
      ],
      
      "maximumIoStreams": {
        "limitIoStreams": true,
        "streamsPerVolume": 75
      }
      
    },
    "relationships": {
      "storageServers": {
        "data": [
          {
            "type": "storageServer",
            "id": "PureDisk:server.domain"
          }
        ]
      }
    }
  }
}



Dick Visser

unread,
Dec 13, 2019, 6:16:46 PM12/13/19
to ansible...@googlegroups.com
You’re sending something that doesn’t work, and you seem to know exactly what the problem is, and also what format _does_ work. So the solution is... send that?

Or am I missing something



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d248f94f-431a-43d7-8ab3-08d9ae619796%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Nicholas Britton

unread,
Dec 13, 2019, 6:47:08 PM12/13/19
to ansible...@googlegroups.com
The problem is I don't know how to make ansible send the right bracket. Testing from swagger I know what it expects. 

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Aci8dPvAc1A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwP%3DaETutURieZSYAD%2B%2B71--zX%2BNHOY4y7EGXLtp98Eozg%40mail.gmail.com.

Stefan Hornburg (Racke)

unread,
Dec 14, 2019, 3:35:55 AM12/14/19
to ansible...@googlegroups.com
On 12/14/19 12:46 AM, Nicholas Britton wrote:
> The problem is I don't know how to make ansible send the right bracket. Testing from swagger I know what it expects. 
>

Hello Nicholas,

try to use a list instead of a dict:

data:
- type: storageServer
id: 'PureDisk:server.domain'

Regards
Racke
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/d248f94f-431a-43d7-8ab3-08d9ae619796%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> Sent from a mobile device - please excuse the brevity, spelling and punctuation.
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Aci8dPvAc1A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwP%3DaETutURieZSYAD%2B%2B71--zX%2BNHOY4y7EGXLtp98Eozg%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwP%3DaETutURieZSYAD%2B%2B71--zX%2BNHOY4y7EGXLtp98Eozg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAN946jTZfpZShJGx5cTP%3D8KcpzFBoyRkZjt3EcufqyZD3OHSmQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAN946jTZfpZShJGx5cTP%3D8KcpzFBoyRkZjt3EcufqyZD3OHSmQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Nicholas Britton

unread,
Dec 14, 2019, 8:22:26 AM12/14/19
to ansible...@googlegroups.com
Is it the - in front of type that makes it a list over a dict?

To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1d07241b-9886-ce52-0ba9-61edcacd8c40%40linuxia.de.

Nicholas Britton

unread,
Dec 14, 2019, 8:34:22 AM12/14/19
to Ansible Project
When i try that i get a syntax error.    

fatal: [127.0.0.1]: FAILED! => {
    "reason": "Syntax Error while loading YAML.\n  did not find expected '-' indicator\n\nThe error appears to be in '/home/nbritton/ansible/gts-core-storage-operations/netbackup/tasks/msdp.create.include.yml': line 78, column 17, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n                - type: storageServer\n                id: 'PureDisk:server'\n                ^ here\nThis one looks easy to fix. It seems that there is a value started\nwith a quote, and the YAML parser is expecting to see the line ended\nwith the same kind of quote. For instance:\n\n    when: \"ok\" in result.stdout\n\nCould be written as:\n\n   when: '\"ok\" in result.stdout'\n\nOr equivalently:\n\n   when: \"'ok' in result.stdout\"\n"
>         To view this discussion on the web visit
>         https://groups.google.com/d/msgid/ansible-project/d248f94f-431a-43d7-8ab3-08d9ae619796%40googlegroups.com
>         <https://groups.google.com/d/msgid/ansible-project/d248f94f-431a-43d7-8ab3-08d9ae619796%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>     --
>     Sent from a mobile device - please excuse the brevity, spelling and punctuation.
>
>     --
>     You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
>     To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Aci8dPvAc1A/unsubscribe.
>     To unsubscribe from this group and all its topics, send an email to ansible...@googlegroups.com
>     <mailto:ansible-project+unsub...@googlegroups.com>.
>     To view this discussion on the web visit
>     https://groups.google.com/d/msgid/ansible-project/CAL8fbwP%3DaETutURieZSYAD%2B%2B71--zX%2BNHOY4y7EGXLtp98Eozg%40mail.gmail.com
>     <https://groups.google.com/d/msgid/ansible-project/CAL8fbwP%3DaETutURieZSYAD%2B%2B71--zX%2BNHOY4y7EGXLtp98Eozg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to

Vladimir Botka

unread,
Dec 14, 2019, 10:19:48 AM12/14/19
to Nicholas Britton, ansible...@googlegroups.com
Hi Nicholas,

On Sat, 14 Dec 2019 05:34:22 -0800 (PST)
Nicholas Britton <britton....@gmail.com> wrote:

> When i try that i get a syntax error.
>
> fatal: [127.0.0.1]: FAILED! => {
> "reason": "Syntax Error while loading YAML.\n

Literal style indicator of the block is missing "|"
https://yaml.org/spec/1.2/spec.html#id2795688

Try:
body: |

instead of

> > > body:
> > > data:
> > > type: diskPool
> > > attributes:
> > > name: server_dpm
> > > diskVolumes:
> > > [name: PureDiskVolume]
> > > maximumIoStreams:
> > > limitIoStreams: true
> > > streamsPerVolume: 75
> > > relationships:
> > > storageServers:
> > > data:
> > > type: storageServer
> > > id: 'PureDisk:server.domain'

Cheers,

-vlado

Vladimir Botka

unread,
Dec 14, 2019, 10:41:45 AM12/14/19
to Nicholas Britton, ansible...@googlegroups.com
Hi Nicholas,

On Sat, 14 Dec 2019 05:34:22 -0800 (PST)
Nicholas Britton <britton....@gmail.com> wrote:

> When i try that i get a syntax error.
>
> fatal: [127.0.0.1]: FAILED! => {
> "reason": "Syntax Error while loading YAML.\n

Indentation is wrong. (Disregard my previous email.)

> > > body:
> > > data:
> > > . type: diskPool
> > > . attributes:
> > > . name: server_dpm
> > > . diskVolumes:
> > > . [name: PureDiskVolume]
> > > . maximumIoStreams:
> > > . limitIoStreams: true
> > > . streamsPerVolume: 75
> > > .relationships:
> > > .storageServers:
> > > data:
> > > type: storageServer
> > > id: 'PureDisk:server.domain'

Cheers,

-vlado

Nicholas Britton

unread,
Dec 14, 2019, 12:48:54 PM12/14/19
to Vladimir Botka, ansible...@googlegroups.com
Okay I can try that. Looks like you added a . In front of each line but the last one that needs to be a list?  Did I see that correct?

Nicholas Britton

unread,
Dec 15, 2019, 12:31:59 AM12/15/19
to Ansible Project
Thank everyone for the help.    Once i lined up the - correctly it worked.  That was a nice trick to learn.


          relationships:
            storageServers:
              data:
              - type: storageServer
                id: "PureDisk:{{mediaserver}}.{{domain}}"
Reply all
Reply to author
Forward
0 new messages