Search code examples
jsonjinja2ansibledevops

How to acces dictionary variable from ansible jinja2 templates?


i want to access the size_available variable from Dict list

"ansible_mounts": [
    {
        "device": "/dev/sda1",
        "fstype": "ext4",
        "mount": "/",
        "options": "rw,errors=remount-ro",
        "size_available": 15032406016,
        "size_total": 20079898624
    }
]

- action: debug msg="mem= {{ ansible_mounts.size_available }}"

TASK [debug] *******************************************************************

fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "'list' object has no attribute 'size_available'"}

Solution

  • Can you please check this, didn't test it:

    - action: debug msg="mem= {{ ansible_mounts[0].size_available }}"