I'm writing an Ansible playbook to configure network teaming and I have the following jinja2 template file in my playbook:
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"}}'
I wanted to know is a there a way to escape the first curly brace of "ports": {{{ ports_list | join(', ') }} as I want Ansible to automatically calculate it to have the following output in the final jinja2 file:
"ports": {"ens1": {}, "ens2": {}}
N.B: I've already tried {{ ports_list | to_json }} and {{ ports_list | join(', ') | to_json }}
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.