Defining complex data (cascaded arrays) in yaml has problems

Moin!

For a recent project I needed to have a data structure with nested arrays, however I could not get it to work using yaml syntax. When using the following playbook:

- hosts: all
   tasks:
     - name: Set some test facts
       set_fact:
         bla: True
         stub: [["mystub.example.net", [["ns1.mystub.example.net", ["192.0.2.4"]]]]]
         stub2:

Moin!

For a recent project I needed to have a data structure with nested arrays, however I could not get it to work using yaml syntax. When using the following playbook:

- hosts: all
tasks:
- name: Set some test facts
set_fact:
bla: True
stub: [["mystub.example.net", [["ns1.mystub.example.net", ["192.0.2.4"]]]]]
stub2:
-
- mystub2,example.net
-
- ns1.mystub2.example.net
-
- 192.0.2.5

<snip />

but IMHO these data structures should be identical. I also tried to put the same yams in a var file with the same result. What am I doing wrong? Any ideas?

The correct syntax for nested list is

  stub2:
    - - mystub2,example.net
      - - - ns1.mystub2.example.net
          - - 192.0.2.5

or

  stub2:

Moin!

Moin!

The correct syntax for nested list is

stub2:
- - mystub2,example.net
- - - ns1.mystub2.example.net
- - 192.0.2.5

or

stub2:
-
- mystub2,example.net
-
-
- ns1.mystub2.example.net
-
- 192.0.2.5

Thanks a lot. That was the trick I was looking for. You missed one array ( the structure is complex ;-).

I don't think I missed an array, but I didn't test it so I did now.

- hosts: localhost
  gather_facts: false
  vars:
    stub: [["mystub.example.net", [["ns1.mystub.example.net", ["192.0.2.4"]]]]]
    stub2:
      - - mystub2,example.net
        - - - ns1.mystub2.example.net
            - - 192.0.2.5
  tasks:
    - debug: var=stub
    - debug: var=stub2

Gives:
TASK [debug] ***********************************
ok: [localhost] => {
    "stub": [
        [
            "mystub.example.net",
            [
                [
                    "ns1.mystub.example.net",
                    [
                        "192.0.2.4"
                    ]
                ]
            ]
        ]
    ]
}

TASK [debug] ***********************************
ok: [localhost] => {
    "stub2": [
        [
            "mystub2,example.net",
            [
                [
                    "ns1.mystub2.example.net",
                    [
                        "192.0.2.5"
                    ]
                ]
            ]
        ]
    ]
}

As you can see thees two are identical.

Fully correct the yams represantion is:

     stub2:
       \-
         \- mystub2,example\.net
         \-
           \-
             \- ns1\.mystub2\.example\.net
             \-
               \- 192\.0\.2\.
     stub2:
       \- \- mystub2,example\.net
         \- \- \- \- ns1\.mystub2\.example\.net
             \- \- 192\.0\.2\.5

but that was easy to fix myself, so thanks again.

But this gives me

TASK [debug] **************************************
ok: [localhost] => {
    "stub3": [
        [
            "mystub2,example.net",
            [
                [
                    [
                        "ns1.mystub2.example.net"
                    ],
                    [
                        "192.0.2.5"
                    ]
                ]
            ]
        ]
    ]
}

And this is *not* the same as your example in your first mail.

Moin!