使用条件语句遇到LXD模板错误

时间:2019-04-03 23:15:46

标签: templates lxd pongo2

我正在尝试通过使用-c "environment.XYZ"向lxc启动中馈入一堆变量来动态创建一个netplan配置文件...在简单情况下,这还是可以的,但是由于某些原因,lxc在第79行的第79行吠叫,表示它宁愿在第一个is ...

之后有一个右括号
EROR[04-04|10:02:36] The start hook failed container=test err="Failed to render template: [Error (where: parser) in <string> | Line 8 Col 79 near 'is'] Closing bracket expected after expression"

这是模板。

network:
        version: 2
        renderer: networkd
        ethernets:
                eth0:
                        dhcp4: false
                        dhcp6: false
{% if ( not  config_get("environment.IPv4") or config_get("environment.IPv4") is none ) and ( not config_get("environment.IPv6") or  config_get("environment.IPv6") is none ) %}
                        addresses: []
{% else %}
                        addresses:
{% if config_get("environment.IPv4") is not none %}
                                - {{ config_get("environment.IPv4", "xxx.yyy.zzz.252") }}/{{ config_get("environment.IPv4netmask", "24") }}
{% endif %}
{% if config_get("environment.IPv6") is not none %}
                                - {{ config_get("environment.IPv6", "xxx.yyy.zzz::252") }}/{{ config_get("environment.IPv6netmask", "64") }}
{% endif %}
{% endif %}
{% if config_get("environment.IPv4") is not none %}
                        gateway4: {{ config_get("environment.IPv4gateway", "xxx.yyy.zzz.1") }}
{% endif %}
{% if config_get("environment.IPv6") is not none %}
                        gateway6: {{ config_get("environment.IPv6gateway", "xxx.yyy.zzz::1") }}
{% endif %}
                        nameservers:
                                addresses:
                                        - xxx.yyy.zzz.2
                                        - xxx.yyy.zzz.2
                                        - 1.1.1.1
                                search:
                                        - internal.example.com
                                        - example.biz

我将其简化版本输入了Jinja2 live parser,这似乎让它很满意。这里简化表示将config_get("environment.IPv6")之类的结构替换为environment.IPv6,因为实时解析器对config_get()一无所知。

如何消除该错误?

0 个答案:

没有答案