Loop over Ansible variable array in Jinja2 template
You have a simple syntax error; you should be using brace brackets instead of parentheses.
You currently have:
(% for mounts in {{ ansible_mounts }} %)
Mountpoint: {{ ansible_mounts.mount }}
(% endfor %)
These should be braces, not parentheses, that is, {%
and %}
.
Further, the variable name you selected in for
is mounts
, so that is what you should be actually using inside the loop to get each object.
Finally, the braces around the variable in the for loop aren't necessary.
Correcting these errors results in this, which should work fine:
{% for mounts in ansible_mounts %}
Mountpoint: {{ mounts.mount }}
{% endfor %}