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.



On Fri, 6 Mar 2020 at 08:04, Shifa Shaikh <shifa...@gmail.com> wrote:

> 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 %}
> <table bgcolor="{{ layer.bgcolor | list}}">
> <tr>
> <th> </th>
> {% for item in layer.things %}
> <th align="center">{{ item }}</th>
> {% endfor %}
> </tr>
> </table>
> {% endfor %}
>
> I run this with the below playbook:
>
> ---
>   - name: Demonstrating variables in Jinja2 Loops
>     hosts: localhost
>     connection: local
>     vars_files:
>       - vars.yml
>     gather_facts: no
>     tasks:
>       - name: Create the Jinja2 based templateone
>
>         template: src=./varloop_new.j2 dest=./output.txt
>
>
>
> The output recieved has a problem.
>
> Output.txt:
>
> -bash-4.2$ cat output.txt
> <table bgcolor="[u'sky blue']">
> <tr>
> <th> </th>
> <th align="center">cactus</th>
> <th align="center">lotus</th>
> <th align="center">jasmine</th>
> <th align="center">rose</th>
> </tr>
> </table>
> <table bgcolor="[u'yellow']">
> <tr>
> <th> </th>
> <th align="center">mango</th>
> <th align="center">apple</th>
> </tr>
> </table>
>
>
> It displays bgcolor="[u'sky blue']" instead of bgcolor="sky blue"
>
> How can I convert the list to a string in the jinja template.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/10765862-e99b-44bf-bdb8-0db36c1fc49b%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/10765862-e99b-44bf-bdb8-0db36c1fc49b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Mark Whaite, Systems Administrator
Adelard LLP
Adelard LLP, Units 24 Waterside, 44-48 Wharf Road, London N1 7UX
Tel: 020 7832 5850
Web: http://www.adelard.com

This e-mail, and any attachments, is confidential and for the use of the
addressee only. If you are not the intended recipient, please telephone 020
7832 5850. We do not accept legal responsibility for this e-mail or any
viruses.

Registered office: Stourside Place, Station Road, Ashford, Kent TN12 1PP
Registered in England & Wales no. OC 304551. VAT no. 454 489808

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAHtMyqgUtd%2BYD1%3DKuw5p89vUW_-EFdgRr%2BUPg%3D-pA7bF7N8xxw%40mail.gmail.com.

Reply via email to