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

后端 未结 8 508
伪装坚强ぢ
伪装坚强ぢ 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:42

    Following worked for me

    ('{{ iplist | join('\',\'') }}')
    

    Ex:

    Inventory
    
    [ips]
    1.1.1.1
    2.2.2.2
    3.3.3.3
    
    #cat temp.sh.j2 
    
     "ips": (ip='{{ groups['zoo'] | join('\',\'') }}') 
    
    result:
    
    #cat temp.sh
    
     "ips": (ip='1.1.1.1','2.2.2.2','3.3.3.3')
    

    Hope it would help someone.

提交回复
热议问题