Cloud-init network configuration with Ubuntu (--cicustom option)

koval

Well-Known Member
Dec 19, 2017
31
0
46
35
Hello,
I am trying to configure network with cloud-init.

I've prepared template with cloud-init with the following option:

Code:
qm set 8000 --cicustom "user=local:snippets/userconfig.yaml,vendor=local:snippets/cloudinit-vendor.yml"

cloudinit-vendor.yml:

Code:
cat cloudinit-vendor.yml
#cloud-config
manage_etc_hosts: true


#
network:
  version: 2
  ethernets:
    ens18:
      dhcp4: true

# locale: de_DE.UTF-8
timezone: Europe/Warsaw
package_update: true
package_upgrade: true
package_reboot_if_required: true
packages:
  - qemu-guest-agent
  - nfs-common
  # - postfix
  - ntp
  # - landscape-client
  - apt-transport-https
  - mc

Code:
ubuntu@ubuntu:~$ cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2

Code:
ubuntu@ubuntu:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens18: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 7e:f5:25:f2:93:66 brd ff:ff:ff:ff:ff:ff
    altname enp0s18

I expect that my network interface will work with DHCP.
Can someone help me please ?

PVE Virtual Environment 7.2-11
cloud-init --version
/usr/bin/cloud-init 22.2-0ubuntu1~22.04.3
 
Last edited:
All you get is `network: version: 2` in the network config file?

There seems to be an issue with the network configuration then. Have you checked the cloud-init logs in /var/log for any errors?
 
All you get is `network: version: 2` in the network config file?
Yes. Only `network: version: 2` .

Here is log from cloud-init

Bash:
 sudo cat /var/log/cloud-init.log | grep network
2022-09-26 12:44:18,634 - __init__.py[DEBUG]: Update datasource metadata and network config due to events: boot-new-instance
2022-09-26 12:44:18,634 - util.py[DEBUG]: Reading from /var/lib/cloud/seed/nocloud/network-config (quiet=False)
2022-09-26 12:44:18,634 - util.py[DEBUG]: Reading from /var/lib/cloud/seed/nocloud-net/network-config (quiet=False)
2022-09-26 12:44:18,723 - util.py[DEBUG]: Reading from /run/cloud-init/tmp/tmptb4fnk1p//network-config (quiet=False)
2022-09-26 12:44:18,724 - util.py[DEBUG]: Read 119 bytes from /run/cloud-init/tmp/tmptb4fnk1p//network-config
2022-09-26 12:44:18,769 - networking.py[DEBUG]: net: all expected physical devices present
2022-09-26 12:44:18,769 - stages.py[INFO]: Applying network configuration from ds bringup=False: {'version': 1, 'config': [{'type': 'nameserver', 'address': ['SENSITIVE_INFO'], 'search': ['SENSITIVE_INFO']}]}
2022-09-26 12:44:18,770 - util.py[DEBUG]: Writing to /run/cloud-init/sem/apply_network_config.once - wb: [644] 24 bytes
2022-09-26 12:44:18,934 - __init__.py[DEBUG]: Not bringing up newly configured network interfaces
2022-09-26 12:44:19,222 - handlers.py[DEBUG]: start: init-network/check-cache: attempting to read from cache [trust]
2022-09-26 12:44:19,224 - handlers.py[DEBUG]: finish: init-network/check-cache: SUCCESS: restored from cache with run check: DataSourceNoCloud [seed=/dev/sr0][dsmode=net]
2022-09-26 12:44:19,255 - stages.py[DEBUG]: Allowed events: {<EventScope.NETWORK: 'network'>: {<EventType.BOOT_NEW_INSTANCE: 'boot-new-instance'>}}
2022-09-26 12:44:19,255 - stages.py[DEBUG]: Event Denied: scopes=['network'] EventType=boot-legacy
2022-09-26 12:44:19,255 - stages.py[DEBUG]: No network config applied. Neither a new instance nor datasource network update allowed
2022-09-26 12:44:19,256 - handlers.py[DEBUG]: start: init-network/setup-datasource: setting up datasource
2022-09-26 12:44:19,256 - handlers.py[DEBUG]: finish: init-network/setup-datasource: SUCCESS: setting up datasource
2022-09-26 12:44:19,267 - handlers.py[DEBUG]: start: init-network/consume-user-data: reading and applying user-data
2022-09-26 12:44:19,271 - handlers.py[DEBUG]: finish: init-network/consume-user-data: SUCCESS: reading and applying user-data
2022-09-26 12:44:19,271 - handlers.py[DEBUG]: start: init-network/consume-vendor-data: reading and applying vendor-data

I think this string points to an error:
Code:
2022-09-26 12:44:18,769 - stages.py[INFO]: Applying network configuration from ds bringup=False: {'version': 1, 'config': [{'type': 'nameserver', 'address': ['SENSITIVE_INFO'], 'search': ['SENSITIVE_INFO']}]}
 
Try adding a network script in addition to the vendor script and try again.
 
  • Like
Reactions: koval
Try adding a network script in addition to the vendor script and try again.
Code:
--cicustom "user=local:snippets/userconfig.yaml,vendor=local:snippets/cloudinit-vendor.yml,network=local:snippets/cloudinit-network.yml"

Resolved my problem,

Thanks!
 
Yes, if you don't specify a snippet, it will use the VM config to generate the cloud-init configs. So even if it is empty, set a snippet if you don't want to autogenerate any configs based on the VM config.
 
  • Like
Reactions: koval