How to iterate over below hash

Hello,

I am new to ansible, i have requirement.

vars:
locations:
  - parentlocation: A
    childlocation:
     - a1
     - a2
     - a3
- parentlocation: B
   childlocation:
     - b1
     - b2
     - b3

Now i want run task so

- name: create parent location
command:
  some command '{{ parentlocation }}' create

- name: create child loc aslo pass parent of it
  command:
    some command '{{ parentlocation }}' --child '{{ childlocation[0,1,3..]

How do i iterate ??

Basically i wilk create parent locatuon and when i create child location i need to pass its parent as well so it creates hierarchies

Thanks,
Dj