We are writing a for
loop in Jinja2, which will keep on concatenating the list variable to a string until the end of the list.We are storing the string to a variable. After the loop completes, we want to print the variable.
The code to perform that is as follows
{% set HOSTLIST = groups['master'] | map('extract', hostvars, ['ansible_default_ipv4', 'address'])| list %}
{% set TEST = "spark://" %}
{% for host in HOSTLIST %}
{% set sample = TEST + host %}
{% set TEST = sample+',' %}
{% endfor %}
{{ TEST }}
Can anybody point me, where we are doing a mistake.
Our output is as follows:
spark://
But the expected output should be like:
spark://192.168.49.111:7077,192.168.49.112:7077,