Im trying to use cloud-init to setup kvm guests (currently Debian 11 and CentOS Stream 8), and I am looking for help in correcting the meta-data and user-data files.
Everything else seems to work, but network interface settings aren't set, though I do see cloud-init logs showing that they are.
Please see below:
For debian:
cat << EOF > /var/lib/libvirt/images/$meta_data_file
instance-id: $vm_name
local-hostname: $vm_name
hostname: $vm_name
fqdn: $vm_name
manage_etc_hosts: true
EOF
cat << EOF > /var/lib/libvirt/images/$cloud_config_file
#cloud-config
# Hostname management
preserve_hostname: false
hostname: $vm_name
fqdn: $vm_name
network:
version: 2
ethernets:
eth0:
match:
name: e*
dhcp4: false
addresses:
- 10.10.0.25/24
gateway4: 10.10.0.254
nameservers:
addresses:
- 10.50.0.23
- 10.50.0.17
- 10.50.0.18
search: [testing,production,admin,internal]
routes:
- to: 10.50.0.0/24
via: 10.10.0.249
users:
- default
- name: admin
sudo: ALL=(ALL) NOPASSWD:ALL
groups: wheel, sudo, admin
home: /home/admin
shell: /bin/bash
hashed_passwd: $adminpasswd
lock_passwd: false
ssh_pwauth: True
chpasswd: { expire: False }
ssh-authorized-keys:
- ssh-rsa ...
- ssh-rsa ...
# only cert auth via ssh (console access can still login)
ssh_pwauth: True
disable_root: false
chpasswd:
list: |
root:$rtpwd
expire: False
runcmd:
# disable dhcp for eth0
- [ sh, -c, sed -e '/iface eth0 inet dhcp/s/^/#/g' -i /etc/network/interfaces ]
bootcmd:
- cloud-init-per always fix-debian-autonet rm /etc/udev/rules.d/75-cloud-ifupdown.rules
- cloud-init-per always fix-debian-netconfig rm /run/network/interfaces.d/*
- cloud-init-per once ifdown ifdown ens3
- cloud-init-per once bugfix rm /run/network/interfaces.d/ens3
- cloud-init-per once ifup ifup ens3
# Configure where output will go
output:
all: ">> /var/log/cloud-init.log"
# configure interaction with ssh server
ssh_svcname: ssh
ssh_deletekeys: True
ssh_genkeytypes: ['rsa', 'ecdsa']
package_update: true
package_upgrade: true
packages:
- bind9-utils
- vim
- freeipa-client
- cloud-utils-growpart
power_state:
delay: "+2" #minutes
mode: reboot
message: Run completed
timeout: 120 #seconds
condition: True
EOF
For Centos Stream 8:
cat << EOF > /var/lib/libvirt/images/$cloud_config_file
#cloud-config
# Hostname management
preserve_hostname: false
hostname: $vm_name
fqdn: $vm_name
network:
version: 2
ethernets:
eth0:
match:
name: e*
dhcp4: false
addresses:
- 10.50.0.26/24
gateway4: 10.50.0.254
nameservers:
addresses:
- 10.15.0.23
- 10.15.0.17
- 10.15.0.18
search: [testing,production,admin,internal]
routes:
- to: 10.15.0.0/24
via: 10.50.0.249
users:
- default
- name: admin
sudo: ALL=(ALL) NOPASSWD:ALL
groups: wheel, sudo, admin
home: /home/admin
shell: /bin/bash
hashed_passwd: $adminpasswd
lock_passwd: false
ssh_pwauth: True
chpasswd: { expire: False }
ssh-authorized-keys:
- ssh-rsa ...
- ssh-rsa ...
ssh_pwauth: True
disable_root: false
chpasswd:
list: |
root:$rtpwd
expire: False
# Configure where output will go
output:
all: ">> /var/log/cloud-init.log"
# configure interaction with ssh server
ssh_svcname: ssh
ssh_deletekeys: True
ssh_genkeytypes: ['rsa', 'ecdsa']
package_update: true
package_upgrade: true
packages:
- bind9-utils
- vim
- freeipa-client
- cloud-utils-growpart
power_state:
delay: "+2" #minutes
mode: reboot
message: Run completed
timeout: 120 #seconds
condition: True
EOF
Please what am I doing wrong?