Lxd ubuntu templates

Hi,

I’m trying to make my template for ubuntu 18.04 netplan more flexible (by popular demand).

I changed:

network:
        version: 2
        renderer: networkd
        ethernets:
                eth0:
                        dhcp4: false
                        dhcp6: false
                        addresses:
                                - {{ config_get("environment.IPv4", "xxx.yyy.zzz.252") }}/{{ config_get("environment.IPv4netmask", "24") }}
                                - {{ config_get("environment.IPv6", "xxx:yyy:zzz::252") }}/{{ config_get("environment.IPv6netmask", "64") }}
                        gateway4: {{ config_get("environment.IPv4gateway", "xxx.yyy.zzz.1") }}
                        gateway6: {{ config_get("environment.IPv6gateway", "xxx.yyy.zzz::1") }}
                        nameservers:
                                addresses:
                                        - 8.8.8.8
                                        - 8.9.8.9
                                        - 1.1.1.1
                                search:
                                        - internal.example.tech
                                        - example.com

to:

network:
        version: 2
        renderer: networkd
        ethernets:
                eth0:
                        dhcp4: false
                        dhcp6: false
{% if config_get("environment.IPv4") is none and 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.yyyy.zzz.1") }}
{% endif %}
{% if config_get("environment.IPv6") is not none %}
                        gateway6: {{ config_get("environment.IPv6gateway", "xxx.yyy.zzz::1") }}
{% endif %}
                        nameservers:
                                addresses:
                                        - 8.8.8.8
                                        - 8.9.8.9
                                        - 1.1.1.1
                                search:
                                        - internal.example.tech
                                        - example.com

This throws:

lxc info --show-log local:test
Name: test
Remote: unix://
Architecture: x86_64
Created: 2019/04/03 01:16 UTC
Status: Stopped
Type: persistent
Profiles: default

Log:

lxc test 20190403011650.963 ERROR    conf - conf.c:run_buffer:335 - Script exited with status 1
lxc test 20190403011650.963 ERROR    start - start.c:lxc_init:859 - Failed to run lxc.hook.pre-start for container "test"
lxc test 20190403011650.963 ERROR    start - start.c:__lxc_start:1905 - Failed to initialize container "test"
lxc test 20190403011650.963 ERROR    lxccontainer - lxccontainer.c:wait_on_daemonized_start:833 - No such file or directory - Failed to receive the container state

How do I find out what it dislikes?

Cheers,
Tink

(I edited your text and changed the quoted environment to preformatted environment. Click to edit your initial post to see how it is done. Hint: I enclose the text with three backticks)

1 Like

Maybe using debug mode could help ? don’t know if you are using classic lxd or snap (should be snap set lxd daemon.debug=true)

Try running lxc monitor --type=logging --pretty in a separate shell while launching the container.

This will hopefully show you the pango error (not that they’re particularly great usually).

1 Like

Thank you Simos :slight_smile:

Thank you very much Stéphane, this is proving most helpful!
It spat out line and column of the statement which it’s swearing about. :slight_smile:

Hmmm … so I did some (limited) testing with an online validator (limited as that validator knows nothing about get_config()) … I now have something that does what I want inside the online playpen, but lxc still says njet when I get to

{% 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 ) %}

The start hook failed container=test err=“Failed to render template: [Error (where: parser) in | Line 8 Col 79 near ‘is’] Closing bracket expected after expression”

That’s the is I rendered bold above.

What am I doing wrong? :confused:

Cheers,
Tink