Ansible逃脱了花括号的一连串

时间:2017-06-19 12:43:27

标签: regex ansible jinja2 curly-braces

我正在编写一个Ansible手册来配置网络组合,我的剧本中有以下jinja2模板文件:

DEVICE=team0
DEVICETYPE=Team
ONBOOT=yes
BOOTPROTO=none
IPADDR="{{ ip }}"
PREFIX="{{ prefix }}"
GATEWAY="{{ gateway }}" 
TEAM_CONFIG='{"runner": {"name": "loadbalance"}, "tx_hash": ["eth", "ipv4"], "ports": {{{ ports_list | join(', ') }}}, "link_watch": {"name": "ethtool"}}'

我想知道有没有办法逃脱“ports”的第一个大括号:{{{ports_list | join(',')}}因为我希望Ansible自动计算它以在最终的jinja2文件中得到以下输出:

"ports": {"ens1": {}, "ens2": {}}

N.B:我已经尝试{{ports_list | to_json}}和{{ports_list |加入(',')| to_json}}

1 个答案:

答案 0 :(得分:0)

Seems like you are looking for to_json filter:

"ports": {{ ports_list | to_json }}

I guess you may want to apply it to whole config object.