Jinja2: format + join the items of a list

前端 未结 4 2256
無奈伤痛
無奈伤痛 2021-02-12 12:42

play_hosts is a list of all machines for a play. I want to take these and use something like format() to rewrite them like rabbitmq@%s and

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-12 13:35

    You could simply join not only by , but also add the prefix together with it. Now that's not very pythonic or sophisticated but a very simple working solution:

    [rabbitmq@{{ play_hosts | join(', rabbitmq@') }}]
    

提交回复
热议问题