Bootstrap FreeKB - Ansible - Create a nested List
Ansible - Create a nested List

Updated:   |  Ansible articles

Here is how you can create a nested list. In this example, using the vars plugin, the "food" key is an list and the "fruit" key is a child list as indicated by the bracket characters [ ]. The debug module is used to output the entire list.

---
- hosts: localhost
  gather_facts: false
  vars:
    food:
      - fruit:
        - apple
        - banana
        - orange
        - grapes
  tasks:
  - debug:
      var: food
...

 

Which should return the following, were we can see that the "food" key is an list and the "fruit" key is a nested list.

ok: [localhost] => {
    "food": [
        {
            "fruit": [
                "apple", 
                "banana", 
                "orange", 
                "grapes"
            ]
        }
    ]
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 9d46a4 in the box below so that we can be sure you are a human.