'Read yaml file into Jinja2 template

I am trying to read a list of ip from a yaml file and render them with jinja2 like: a.yml:

server_ips:
  - 192.168.1.1
  - 192.168.1.2
  - 192.168.1.3

Expected results after rendering:

server_ips = ["192.168.1.1", "192.168.1.2", "192.168.1.3"]

However, what I got for now is like:

server_ips = ['192.168.1.1', '192.168.1.2', '192.168.1.3']

What I worte in the jirja2 file is like:

{% set start_join = [] %}
{% for ip in server_ips %}
    {{ start_join.append(ip)}}
{% endfor %}
start_join = {{ start_join }}

So is there any way I could turn the single quote to double quotes in the list?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source