问题
结论:我让它完成了大部分自动安装(我想是吧?),但它在完成自动安装后一直弹出 GUI 安装。想知道为什么它一直弹出 GUI。/TLDR
较长版本:我正在尝试弄清楚如何使用 Hashicorp Packer 将 ubuntu(以及最终的其他发行版)部署到 Proxmox。我已经设置了大部分配置并开始工作……怎么样?它成功“部署”了,但无法完成初始设置,它继续进行自动安装,但仍然会启动 GUI 安装。从手动逐步完成 GUI,在完成自动安装部分后,似乎所有内容都已填写(减去用户身份部分,即全名/用户名/等)。它似乎甚至不需要找到 IP 地址,就像您只通过 GUI 时一样,所以我认为 DHCP 工作正常?
我尝试过查看其他一些类似的问题,但它们的解决方案对我来说还没有用(目前)。
- 无法使用 Ubuntu 服务器 20-04 运行自动安装
- 自动安装-ubuntu-server-20-04-无法自动安装
- 在安装打包程序云初始化上下文期间为 ubuntu-20-04 分配 IP
- 通过 pxelinux-cloud-init 在裸机或 VirtualBox VM 上部署 ubuntu-20-04(不过我不太确定从这个中能学到什么)
理论
我有几种理论,但似乎都不太正确,或者我不知道如何验证它们。
- 我忘记了
user-data
(yaml)中的某些内容,因此它尝试调出 GUI。 - 我在文件中缺少一些
.pkr.hcl
proxmox 正确设置 vm 所需的配置参数? - 我使用的 Ubuntu 版本有些奇怪,也许我需要不同的 ISO?但我读过的东西只是说云初始化
preseed.cfg
功能只是将(yaml)文件的遗留内容替换掉user-data
,所以我对这个理论表示怀疑。 - 我需要设置一些内核功能吗?说实话,我不知道从哪里开始,我也非常确定如果是这样的话,我会在其他地方看到一些相关信息。但是,也许我只是在错误的地方寻找?
- 该
user-data
文件没有被正确加载到 Ubuntu 中?
充满希望的结果
- 如果你知道神奇的酱汁,请赐予我吧:)
- 如果您知道如何让 Ubuntu 20.04 在安装过程中重定向其部分日志,以便我可以更深入地了解,那将不胜感激!更好的打包程序日志记录也是如此(除了
-debug
,我已经尝试过了)。我试过了/var/log/installer
,但我认为我没有完全掌握发生了什么。但除了 SSH 密钥错误之外,我没有看到任何故障,也看不到任何user-data
下载或下载失败的迹象。 - 如果您对如何验证我的某些理论或任何其他理论有任何想法,我很乐意听到!
- 如果您发现我在以下配置文件中做错了什么,请指出!几天来,我一直在 SILO 中尝试这样做,但遇到了瓶颈,我不知道该如何克服
更新(持续进行)
seed from http://192.168.0.144:80/user-data not supported by DataSourceNoCloud [seed=None][dsmode=net]
在/var/log/cloud-init.log
调查为什么会出现这种情况时发现,任何建议都将不胜感激:)- 好的,我弄清楚了为什么会出现上述错误,似乎它不是正确的 YAML 格式。我只是将文件转储到 YAML 格式化程序中,然后将其复制粘贴回我的目标文件中。
- 现在的错误是加载的 YAML 文件是空白的
/var/lib/cloud/seed/nocloud/user-data
,再次感谢您的任何建议:)
暗示
如果您足够酷,愿意尝试复制这些内容,或者在它(希望)得到解答之后您偶然发现了这一点,那么使用文件可以让您的生活更轻松example.auto.pkrvars.hcl
。
版本
普罗克斯莫克斯:Proxmox VE 7.1-4
视窗:Windows 10 Pro : 10.0.19043.0
打包机:1.7.10
Example.pkr.hcl
packer {
required_plugins {
proxmox = {
version = " >= 1.0.1"
source = "github.com/hashicorp/proxmox"
}
}
}
source "proxmox-iso" "proxmox-ubuntu-20" {
proxmox_url = "https://proxmox.lan:8006/api2/json"
vm_name = "packer-ubuntu-20"
iso_url = "http://iso.repo.lan/ubuntu-20.04.3-live-server-amd64.iso"
iso_checksum = "f8e3086f3cea0fb3fefb29937ab5ed9d19e767079633960ccb50e76153effc98"
username = "${var.pm_user}"
password = "${var.pm_pass}"
token = "${var.pm_token}"
node = "proxmox"
iso_storage_pool = "local"
ssh_username = "${var.ssh_user}"
ssh_password = "${var.ssh_pass}"
ssh_timeout = "20m"
ssh_pty = true
ssh_handshake_attempts = 20
boot_wait = "5s"
http_directory = "http" # Starts a local http server, serves Preseed file
boot_command = [
"<esc><wait><esc><wait><f6><wait><esc><wait>",
"<bs><bs><bs><bs><bs>",
"ip=${cidrhost("192.168.0.0/24", 9)}::${cidrhost("192.168.0.0/24", 1)}:${cidrnetmask("192.168.0.0/24")}::::${cidrhost("192.168.0.0/24", 1)} ",
"autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/",
"--- <enter>"
]
insecure_skip_tls_verify = true
template_name = "packer-ubuntu-20"
template_description = "packer generated ubuntu-20.04.3-server-amd64"
unmount_iso = true
pool = "packer"
memory = 4096
cores = 1
sockets = 1
os = "l26"
qemu_agent = true
cloud_init = true
# scsi_controller = "virtio-scsi-pci"
disks {
type = "scsi"
disk_size = "30G"
storage_pool = "local-lvm"
storage_pool_type = "lvm"
format = "raw"
}
network_adapters {
bridge = "vmbr0"
model = "virtio"
firewall = true
# vlan_tag = 1
}
}
build {
sources = ["source.proxmox-iso.proxmox-ubuntu-20"]
provisioner "shell" {
inline = [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
"ls /"
]
}
}
vars.pkr.hcl
variable "pm_user" {
type = string
description = "Proxmox User Name"
default = "packer@pam!<api-tag>"
}
variable "pm_pass" {
type = string
description = "Proxmox User Password"
default = "packer"
}
variable "pm_token" {
type = string
description = "Proxmox API Token"
}
variable "ssh_user" {
type = string
description = "SSH User"
default = "packer"
}
variable "ssh_pass" {
type = string
description = "SSH Password"
default = "packer"
}
variable "vm_name" {
type = string
description = "VM Name"
default = "packer_hostname"
}
http/user-data
autoinstall:
version: 1
locale: en_US.UTF-8
keyboard:
layout: en
variant: us
identity:
hostname: packer-ubuntu-20
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0" #ubuntu
username: ubuntu
realname: ubuntu
refresh-installer:
update: false
ssh:
install-server: yes
allow-pw: yes
packages:
- qemu-guest-agent
storage:
layout:
name: direct
swap:
size: 0
来源
https://www.aerialls.eu/posts/ubuntu-server-2004-image-packer-subiquity-for-proxmox/
https://ubuntu.com/server/docs/install/autoinstall-reference
https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
https://cloudinit.readthedocs.io/en/latest/topics/modules.html#write-files
https://cloudalbania.com/posts/2022-01-homelab-with-proxmox-and-packer/
答案1
回答
幸运的是,我搜索的方向完全错误。
问题是我没有读过云初始化 常见问题解答足够接近了。我所要做的就是将其添加#cloud-config
到文件的第一行user-data
。
对于任何感兴趣的人而言,下面的配置都是有用的。
我把完整的文档放在这里。如果感兴趣的话可以随意阅读 https://github.com/aRustyDev/packer
Example.pkr.hcl
packer {
required_plugins {
proxmox = {
version = " >= 1.0.1"
source = "github.com/hashicorp/proxmox"
}
}
}
source "proxmox-iso" "proxmox-ubuntu-20" {
proxmox_url = "https://proxmox.lan:8006/api2/json"
vm_name = "packer-ubuntu-20"
iso_url = "http://iso.repo.lan/ubuntu-20.04.3-live-server-amd64.iso"
iso_checksum = "f8e3086f3cea0fb3fefb29937ab5ed9d19e767079633960ccb50e76153effc98"
username = "${var.pm_user}"
password = "${var.pm_pass}"
token = "${var.pm_token}"
node = "proxmox"
iso_storage_pool = "local"
ssh_username = "${var.ssh_user}"
ssh_password = "${var.ssh_pass}"
ssh_timeout = "20m"
ssh_pty = true
ssh_handshake_attempts = 20
boot_wait = "5s"
http_directory = "http" # Starts a local http server, serves Preseed file
boot_command = [
"<esc><wait><esc><wait><f6><wait><esc><wait>",
"<bs><bs><bs><bs><bs>",
"ip=${cidrhost("192.168.0.0/24", 9)}::${cidrhost("192.168.0.0/24", 1)}:${cidrnetmask("192.168.0.0/24")}::::${cidrhost("192.168.0.0/24", 1)} ",
" autoinstall ds=nocloud-net;s=http://httpd.proxmox.local:80/preseed/ubuntu-20/ ",
"--- <enter>"
]
insecure_skip_tls_verify = true
template_name = "packer-ubuntu-20"
template_description = "packer generated ubuntu-20.04.3-server-amd64"
unmount_iso = true
pool = "packer"
memory = 4096
cores = 1
sockets = 1
os = "l26"
qemu_agent = true
disks {
type = "scsi"
disk_size = "30G"
storage_pool = "local-lvm"
storage_pool_type = "lvm"
format = "raw"
}
network_adapters {
bridge = "vmbr0"
model = "virtio"
firewall = true
}
}
build {
sources = ["source.proxmox-iso.proxmox-ubuntu-20"]
provisioner "shell" {
inline = [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
"ls /"
]
}
}
vars.pkr.hcl
variable "pm_user" {
type = string
description = "Proxmox User Name"
default = "packer@pam!<api-tag>"
}
variable "pm_pass" {
type = string
description = "Proxmox User Password"
default = "packer"
}
variable "pm_token" {
type = string
description = "Proxmox API Token"
}
variable "ssh_user" {
type = string
description = "SSH User"
default = "packer"
}
variable "ssh_pass" {
type = string
description = "SSH Password"
default = "packer"
}
variable "vm_name" {
type = string
description = "VM Name"
default = "packer_hostname"
}
http/user-data
#cloud-config
autoinstall:
version: 1
locale: en_US.UTF-8
keyboard:
layout: en
variant: us
identity:
hostname: packer-ubuntu-20
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0" #ubuntu
username: ubuntu
realname: ubuntu
refresh-installer:
update: false
ssh:
install-server: yes
allow-pw: yes
packages:
- qemu-guest-agent
storage:
layout:
name: direct
swap:
size: 0