Following @simos splendid guide, I have set the following profile I’d like to use:
lxc profile show kcloudinit
config:
user.network-config: |
network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.XXX/24]
gateway4: 192.168.1.YYY
nameservers:
addresses: [192.168.1.YYY]
user.user-data: |
#cloud-config
package_upgrade: true
packages:
- python
users:
- name: root
ssh_authorized_keys:
- ssh-rsa key1
- ssh-rsa key2
description: Default LXD profile
devices:
eth0:
name: eth0
nictype: bridged
parent: br0
type: nic
root:
path: /
pool: default
type: disk
name: kcloudinit
used_by: []
However, when I launch lxc launch -p kcloudinit ubuntu:18.04 test-01-kcloudinit it doesn’t work: /etc/netplan/ directory inside the container is empty, ssh-keys are not set and python package is not installed. Here I provide log files:
If I split my configuration like this:
cat net.yml
version: 2
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.131/24]
gateway4: 192.168.1.201
nameservers:
addresses: [192.168.1.201]
cat userdata.yml
#cloud-config
package_upgrade: true
packages:
- python
users:
- name: root
ssh_authorized_keys:
- ssh-rsa key1
- ssh-rsa key2
and then launch:
lxc launch -p default -p br0 ubuntu:18.04 test-01-kcloudinit --config=user.network-config="$(cat net.yml)" --config=user.user-data="$(cat userdata.yml)"
everything works as expected: the static IP is set via netplan, python package is installed and ssh authorized_keys are set.
From what I understand after some digging it migth be the problem with some problem that python3 has with formatting yaml file as seen in provided log files:
2018-11-20 11:17:21,677 - util.py[DEBUG]: failed stage init-local
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 658, in status_wrapper
ret = functor(name, args)
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 362, in main_init
init.apply_network_config(bring_up=bool(mode != sources.DSMODE_LOCAL))
File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 671, in apply_network_config
return self.distro.apply_network_config(netcfg, bring_up=bring_up)
File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 178, in apply_network_config
dev_names = self._write_network_config(netconfig)
File "/usr/lib/python3/dist-packages/cloudinit/distros/debian.py", line 114, in _write_network_config
return self._supported_write_network_config(netconfig)
File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 93, in _supported_write_network_config
renderer.render_network_config(network_config)
File "/usr/lib/python3/dist-packages/cloudinit/net/renderer.py", line 56, in render_network_config
templates=templates, target=target)
File "/usr/lib/python3/dist-packages/cloudinit/net/netplan.py", line 202, in render_network_state
content = self._render_content(network_state)
File "/usr/lib/python3/dist-packages/cloudinit/net/netplan.py", line 236, in _render_content
if network_state.version == 2:
AttributeError: 'NoneType' object has no attribute 'version'
Is it really a bug or have I made a mistake in profile settings?