首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Packer将Ubuntu 20.04部署到Proxmox

使用Packer将Ubuntu 20.04部署到Proxmox
EN

Ask Ubuntu用户
提问于 2022-02-04 05:13:15
回答 1查看 2.7K关注 0票数 0

问题

TLDR:我已经完成了大部分AutoInstall (我认为?)但是,在通过AutoInstall之后,它会一直打开GUI安装。寻找任何输入,以了解为什么它会不断地打开GUI。/TLDR

Longer版本:我正在尝试通过使用Hashicorp将ubuntu (以及最终的其他发行版)部署到Proxmox。我已经安排好了大部分的工作.说大也大吧?它成功地“部署”了,但是它无法完成最初的设置,它一直在通过AutoInstall,但是仍然会打开GUI安装。从手动遍历GUI开始,在完成AutoInstall部分之后,似乎所有内容都已填写完毕(减去用户标识部分,即FullName/Username/etc)。它似乎甚至不需要找到一个IP地址,就像您刚通过GUI时一样,所以我认为DHCP运行得很好吗?

我试过考虑其他一些类似的问题,但他们的解决方案对我来说还不管用。

理论

我有一些理论,但似乎没有一个理论是正确的,或者我不知道如何检验它们。

  1. 我忘记了user-data (yaml)中的一些东西,因为它试图打开GUI。
  2. 我在.pkr.hcl文件中缺少了一些配置参数,这是proxmox正确设置vm所必需的吗?
  3. 我使用的Ubuntu版本有些奇怪,也许我需要一个不同的ISO?但我所读到的内容只是说,Cloud功能只是将遗留的preseed.cfg替换为user-data (yaml)文件,所以我对这一理论表示怀疑。
  4. 我需要设置一些内核特性吗?老实说,我不知道从哪里开始,我也很确定,如果是这样的话,我会在其他地方看到一些关于它的东西。但是嘿,也许我只是找错地方了?
  5. user-data文件没有正确加载到Ubuntu中吗?

充满希望的结果

  1. 如果你知道魔法酱,请用它来优雅我:)
  2. 如果您知道如何让Ubuntu20.04在安装过程中重定向它的一些日志,那么我可以进行更深入的研究,这将是非常感谢的!对于更好的封隔器日志也是如此(除了-debug之外,我已经尝试过了)。我试过/var/log/installer,但我不认为我对发生了什么事情有很强的把握。但是,除了SSH键错误之外,我没有看到任何故障,也看不到任何user-data下载或下载失败的迹象。
  3. 如果你对如何测试我的一些理论或任何其他理论有任何想法,我很想听听它们!
  4. 如果你能看到我在下面的配置文件中做错了什么,请指出它们!我已经在筒仓里做了几天了,我不知道该怎么克服

更新(正在进行)

  1. seed from http://192.168.0.144:80/user-data not supported by DataSourceNoCloud [seed=None][dsmode=net] /var/log/cloud-init.log中发现了为什么会出现这种情况,任何建议都将不胜感激:)
  2. 好的,所以我知道了为什么上面的错误发生了,似乎它不是在正确的YAML格式。我只是将文件转储到YAML格式化程序中,然后复制粘贴回我的目标文件中。
  3. 现在,错误是加载的YAML文件是空白的/var/lib/cloud/seed/nocloud/user-data,同样,我希望得到任何建议:)

提示

如果您很酷,可以尝试复制这些东西,或者在它(希望)被回答后偶然发现了这个问题,那么使用example.auto.pkrvars.hcl文件可以让您的生活更轻松。

版本

ProxmoxProxmox VE 7.1-4 WindowsWindows 10 Pro : 10.0.19043.0 封隔器1.7.10

Example.pkr.hcl

代码语言:javascript
复制
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 = [
    "",
    "",
    "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 }}/",
    "--- "
  ]

  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

代码语言:javascript
复制
variable "pm_user" {
  type        = string
  description = "Proxmox User Name"
  default     = "packer@pam!"
}
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

代码语言:javascript
复制
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/

EN

回答 1

Ask Ubuntu用户

发布于 2022-02-05 16:59:39

答案

幸运的是,我在一个完全错误的方向上搜索SMH。问题是,我没有仔细阅读Cloud 常见问题。我所要做的就是添加#cloud-config作为我的user-data文件中的第一行。

对任何感兴趣的人来说,下面的吐露都会奏效。

我把所有的文件都放在这里了。如果有兴趣的https://github.com/aRustyDev/packer,请随意阅读

Example.pkr.hcl

代码语言:javascript
复制
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 = [
    "",
    "",
    "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/ ",
    "--- "
  ]

  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

代码语言:javascript
复制
variable "pm_user" {
  type        = string
  description = "Proxmox User Name"
  default     = "packer@pam!"
}
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

代码语言:javascript
复制
#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
票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1391042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档