Cloud-init and Ubuntu 20.04 with user.network-config

Hello LXD team,

I’m trying to understand the cloud-init portion through lxd for vm’s. I’m trying to push a static ip via cloud-init to a 20.04 vm. It doesn’t seem to run at all if I use user.network-config portion. It seems like I’m missing a step or maybe not grabbing the concept. I was able to get a a static ip via using write_files: in user.user-data: and adding a static stuff there and restarting netapply. That feels a little hacky and not sure if that is the right way.

config:
user.network-config: |
version: 1
config:
- type: physical
name: eth1
subnets:
- type: static
ipv4: true
address: 10.10.101.20
netmask: 255.255.255.0
gateway: 10.10.101.1
control: auto
- type: nameserver
address: 10.10.10.254
description: config
devices:
config:
source: cloud-init:config
type: disk
eth0:
name: eth0
nictype: macvlan
parent: enp0s20f0
type: nic
root:
path: /
pool: lxd_storage
type: disk
name: plex_test
used_by:

  • /1.0/instances/plex-test

Until some fixes happen to the main Ubuntu images, your best change is to use images:ubuntu/20.04/cloud which is an image with a properly enabled agent that does not need the cloud-init:config device you have in your config.

That VM image will run cloud-init with data inserted through the agent which then does support network-config properly.

I was able to create profile but it re-writes in with \n where the lines breaks were

lxc profile show vm27profile
config:
user.network-config: “version: 1\nconfig:\n - type: physical\n name: enp5s0
\n subnets:\n - type: static\n ipv4: true\n address: 172.17.5.27\n
\ netmask: 255.255.0.0\n gateway: 172.17.1.1\n control: auto\n
\ - type: nameserver\n address: 172.17.1.104\n”
user.user-data: “#cloud-config\nssh_pwauth: yes\n\nusers:\n - name: ubuntu \n passwd:
“$6$iBF0eT1/6UPE2u$V66Rk2BMkR09pHTzW2F.4GHYp3Mb8eu81Sy9srZf5sVzHRNpHP99JhdXEVeN0nvjxXVmoA6lcVEhOOqWEd3Wm0”\n
\ lock_passwd: false\n groups: lxd\n shell: /bin/bash\n sudo: ALL=(ALL)
NOPASSWD:ALL\n”
description: LXD profile for virtual machines
devices:
config:
source: cloud-init:config
type: disk
eth0:
name: eth0
nictype: bridged
parent: br0
type: nic
name: vm27profile
used_by:

  • /1.0/instances/testvm27

then I launched the vm with this command
lxc launch --profile default --profile vm27profile ubuntu:20.04 testvm27 --vm