{{ ansiblehostname }} IN A {{ ansible{{netint_dmz_untrusted}}[‘ipv4’][‘address’] }}
你不能使用这样的嵌套表达式,因为Jinja不进行递归计算。为了做你想做的事,请对待
vars
作为一个
dict
并以这种方式查找关键:
{{ ansible_hostname }} IN A {{ vars[“ansible“+net_int_dmz_untrusted][‘ipv4’][‘address’] }}
</code>
另外,虽然你没有问过这个问题,但你真的会更乐意将这些表达式分配给变量,而不是将它们复制粘贴到整个地方:
{# This template defines a named zone based on the dictionnary of the containers metadata #}
{% set theaddr4 = vars[“ansible“+netint_dmz_untrusted][‘ipv4’][‘address’] %}
{% set the_addr6 = vars[“ansible“+net_int_dmz_untrusted][‘ipv6’][‘address’] %}
{{ ansible_hostname }} IN A {{ the_addr4 }}
{{ ansible_hostname }} IN AAAA {{ the_addr6 }}
</code>