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.

Reply via email to