Search code examples
ansiblejinja2trim

Ansible jinja templating trim last character


I want this output ingress = ["aa","bb"]

- name: Create the Jinja2 based template
  template:
    src: "/var/opt/conf.yml.j2"
    dest: "/var/opt/conf.yml"
  with_items: "{{ var }}"


ingress = [{% for item in var.stdout_lines %} "{{ item }}", {% endfor %}]

But I get this with a , at the end of the list

ingress = ["aa","bb",]

How could I trim the last character ,


Solution

  • {% for item in var.stdout_lines %} "{{ item }}" {%if not loop.last %},{% endif %}{% endfor %}