Inventory:
[Test]
local ansible_host=localhost
[Test:vars]
my_clusters="A,B,C"
I'm trying to write a jinja2 template iterating over my_clusters
var.
Over the web mostly I found below way of iterating (Also here For loop in Ansible Template):
{% for item in hostvars[groups['Test'][0]]['my_clusters'].split(',') %}
{{item}}
{% endfor %}
which produces output:
A
B
C
But my requirement is to print string "Cluster" (comma separated on the same line) as many times the no. of items in my_clusters
var.
Expected output:
Cluster,Cluster,Cluster
I tried something like below. But it's not working.
{% set str="" %}
{% for cluster in hostvars[groups['Test'][0]]['my_clusters'].split(',') %}
{% str += "Cluster," %}
{% endfor %}
{{str}}