jinja2获取属性列表 [英] jinja2 get list of attributes
本文介绍了jinja2获取属性列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用salt + jinja2来模板化context.xml文件.我有以下支柱:
I'm using salt + jinja2 to template a context.xml file. I have the following pillar:
context:
db_server: some_server
resources:
some_customer:
name: some_name
user: some_user
passwd: some_passwd
this_customer:
name: this_name
user: this_user
passwd: this_passwd
我需要创建一个字符串,其中包含每个客户的名称列表.现在我有这个:
I need to create a string with a list of the names for each customer. Right now I have this:
{%- set nameList = pillar['context']['resources']|list()|join(', ') %}
这给了我以下列表:'some_customer, this_customer'
.我想要以下列表:'some_name, this_name'
.
This gives me this list: 'some_customer, this_customer'
. I'd like this list: 'some_name, this_name'
.
我该怎么做?
推荐答案
以下一种方法对我有用:
The following one-liner worked for me:
{%- set nameList = pillar['context']['resources'].values()
|map(attribute='name')|join(', ') %}
这篇关于jinja2获取属性列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文