Inventory:
[Test]
local ansible_host=localhost
[Test:vars]
my_clusters=\"A,B,C\"
I\'m trying to write a jinja2 template iterating over m
This can be achieved with assignments introduced in Jinja2 2.10:
{% set ns = namespace(str="") %}
{% for cluster in hostvars[groups['Test'][0]]['my_clusters'].split(',') %}
{% set ns.str = ns.str + "Cluster" %}
{%- if not loop.last %}{% set ns.str = ns.str + "," %}{% endif %}
{% endfor %}
The above answers the question from the title, but there are some syntactical problems with your code:
set
inside the expression,+=
operator,,
.