Add quotes to elemens of the list in jinja2 (ansible)

后端 未结 8 507
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 10:43

I have very simple line in the template:

ip={{ip|join(\', \')}}

And I have list for ip:

ip:
 - 1.1.1.1
 - 2.2.2.2
 - 3.3.3.         


        
8条回答
  •  误落风尘
    2021-01-11 11:32

    try:

    - hosts: localhost
      tags: s20
      gather_facts: no
      vars:
        ip:
          - 1.1.1.1
          - 2.2.2.2
          - 3.3.3.3
        joined_ip: "'{{ \"', '\".join(ip)}}'"
      tasks:
      - debug: msg="(ip={{joined_ip}})"
    

    PS: ansible supports a bit of python code execution within {{}}, which is what i'm misusing here.

提交回复
热议问题