Convert list to string in rendered Jinja template

I have a variable files like below:

`
layers:

  • name: APP
    things:

  • cactus

  • lotus

  • jasmine

  • rose
    bgcolor:

  • sky blue

  • name: WAS
    things:

  • mango

  • apple
    bgcolor:

  • yellow
    `

Below is my jinja template file:

`
{% for layer in layers %}

{% for item in layer.things %} {% endfor %}
{{ item }}
{% endfor %} `

I run this with the below playbook:

`

Hi

You can find all about Jinja filters here https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html

But you can convert a list to a string using

{{ list | join(" ") }}

This will add a space between each element. I am not sure if that is what you need.


I have a variable files like below:

>
layers:
-name:APP
things:
-cactus
-lotus
-jasmine
-rose
bgcolor:
-sky blue

\-name:WAS
  things:
    \-mango
    \-apple
  bgcolor:
    \-yellow

>

Below is my jinja template file:
>
{%forlayer inlayers %}
<table bgcolor="{{ layer.bgcolor | list}}">
<tr>
<th></th>
{% for item in layer.things %}
<th align="center">{{ item }}</th>
{%endfor %}
</tr>
</table>
{%endfor %}
>

Try the join filter {{ layer.bgcolor | join(' ') }}. It is fruitless to apply the list
filter to a list :-).

Regards
        Racke

Thank you @Stefan,

That solves the issue !!