dimanche 11 août 2019

How would I access a nested array in using if condition in Jinja2?

I'm trying to build some logic into my Jinja2 template. The aim is for Jinja2 to evaluate if both variables in a nested/child array have a value, and if so, then run the loop.

My current code works without the if statement, however, I'm struggling to understand how to access the nested array to build the if logic before the loop runs.

In my case, the task for if statement would be to make sure that both ipv4.address and ipv4.mask have a value.

I know I am missing something really silly and easy.

Any help would be appreciated.

I tried multiple methods, but I just don't seem to be able to work out how to access address and mask values within each array.

Current vars, Ansible debug (to show how its nested) and Jinja2 section (working):

interfaces:
  - name: ae10
    ipv4:
      - address: 444.444.444.444
        mask: 8


```

        "interfaces": [
            {
                "ipv4": [
                    {
                        "address": "444.444.444.444",
                        "mask": 8
                    }
                ],
                "name": "ae10"
            }
        ],

Aucun commentaire:

Enregistrer un commentaire