I use these files for make ubuntu 22.04 image by packer but I do not know why after make image VM has not an IP and I can not login to it
Please help to find my mistake
packer {
required_plugins {
qemu = {
version = ">= 1.0.9"
source = "github.com/hashicorp/qemu"
}
}
}
source "qemu" "image" {
http_directory = "files/qemu_http_dir"
boot_command = [
"<spacebar><wait><spacebar><wait><spacebar><wait><spacebar><wait><spacebar><wait>",
"e<wait>",
"<down><down><down><end>",
" autoinstall ds=nocloud-net\\;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/",
"<f10>"
]
boot_wait = "10s"
iso_url = var.iso_url
iso_checksum = var.iso_checksum
memory = var.vm_memory
ssh_password = "packerubuntu"
ssh_username = "admin"
ssh_timeout = "20m"
shutdown_command = "echo 'packerubuntu' | sudo -S shutdown -P now"
headless = true
accelerator = "kvm"
format = "qcow2"
disk_size = var.vm_disk_size
cpus = var.vm_cpu
net_device = "virtio-net"
efi_boot = false
}
build {
name = "image"
sources = [ "source.qemu.image" ]
and
provisioner "shell" {
inline = [ "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for Cloud-Init...'; sleep 1; done" ]
}
provisioner "shell" {
inline = ["df -h > /tmp/df.txt && cat /tmp/df.txt"]
}
provisioner "shell" {
inline = ["lsblk > /tmp/lsblk.txt && cat /tmp/lsblk.txt"]
}
provisioner "shell" {
inline = [
"sudo mkdir -p /opt/dd && sudo chown -R $USER /opt/dd"
]
}
provisioner "file" {
destination = "/opt/dd"
source = "./ansible"
}
provisioner "file" {
destination = "/opt/dd"
source = "./bootstrappers"
}
provisioner "shell" {
environment_vars = ["BASE_IMAGE=${var.vm_name}", "DOCKER_PACKER=${var.docker_packer}"]
execute_command = "env {{ .Vars }} {{ .Path }}"
script = "./bootstrappers/kickstarter.sh"
}
}
and
variable "docker_packer" {
type = string
default = "${env("docker_packer")}" # True / False
}
variable "docker_image" {
type = string
default = "${env("docker_image")}"
}
variable "iso_url" {
type = string
default = "${env("iso_url")}"
}
variable "iso_checksum" {
type = string
default = "${env("iso_checksum")}"
}
variable "vm_name" {
type = string
default = "${env("vm_name")}"
}
variable "vm_memory" {
type = number
default = "${env("vm_memory")}"
}
variable "vm_cpu" {
type = number
default = "${env("vm_cpu")}"
}
variable "vm_disk_size" {
type = string
default = "${env("vm_disk_size")}"
}
variable "username" {
type = string
default = "${env("username")}"
}
variable "password" {
type = string
default = "${env("password")}"
}
and
#cloud-config
autoinstall:
version: 1
locale: en_US
keyboard:
layout: us
ssh:
install-server: true
allow-pw: true
packages:
- qemu-guest-agent
user-data:
preserve_hostname: false
hostname: packerubuntu
package_upgrade: true
timezone: Europe/Berlin
chpasswd:
expire: true
list:
- user1:packerubuntu
users:
- name: admin
passwd: $6$xyz$74AlwKA3Z5n2L6ujMzm/zQXHCluA4SRc2mBfO2/O5uUc2yM2n2tnbBMi/IVRLJuKwfjrLZjAT7agVfiK7arSy/
groups: [adm, cdrom, dip, plugdev, lxd, sudo]
lock-passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
- name: user1
plain_text_passwd: packerubuntu
lock-passwd: false
shell: /bin/bash
network:
network:
ethernets:
ens3:
critical: true
dhcp-identifier: mac
dhcp4: true
dhcp6: false