在Ansible Jinja2模板中,我试图设置"默认"值也有一个变量,但它打印出文字而不是插值。
例如:
homedir = {{ hostvars[inventory_hostname]['instances'][app_instance]['homedir'] | default("/home/{{ app_instance }}/airflow") }}
返回:
airflow_home = /home/{{ app_instance }}/airflow
如何引用app_instance
变量?
答案 0 :(得分:5)
在Jinja2表达式中使用Jinja2语法。您应该将字符串连接到变量值:
outcome =
[{"row":["column1_value1","column1_value11"]},
{"row":["column1_value2","column1_value22"]},
{"row":["column1_value3","column1_value33"]}]
outcome.
map(&:values). # get rid of "row"
map(&:flatten). # get rid of nesting
map(&%i|c1 c2|.method(:zip)). # attach titles
map(&:to_h) # hashify
#⇒ [{:c1=>"column1_value1", :c2=>"column1_value11"},
# {:c1=>"column1_value2", :c2=>"column1_value22"},
# {:c1=>"column1_value3", :c2=>"column1_value33"}]