有没有办法使用 Packer 配置裸机?

Thi*_*sto 10 packer

Packer 可以用于安装和配置裸机服务器吗?Packer 为 Web 服务器提供存储库包和 preseed/kickstart,并且可以运行一些其他配置软件(ansible、puppet、chef 等)。可以用来安装裸机服务器吗?如果是,packer .json 应该是什么样子的?

小智 9

我有一个类似的问题。我在使用 Packer 和 PXE 引导时发现了这个问题线程。

https://github.com/hashicorp/packer/issues/955

瓦西里·托尔斯托夫 (Vasiliy Tolstov) 在帖子中评论道:

[它] 非常简单:在 VM 中安装所有需要的东西(对于 Debian live-boot,对于能够从网络启动的 fedora/centos Dracut)。在[构建] [with] 打包程序之后运行以下脚本(Debian 示例):

#!/bin/sh -ex

apt-get -y install squashfs-tools

mkdir -p /mnt/squashfs /squashfs
mount -o bind / /mnt/squashfs

mksquashfs /mnt/squashfs /squashfs/filesystem.squashfs -comp gzip -no-exports -xattrs -noappend -no-recovery -e 
/mnt/squashfs/squashfs/filesystem.squashfs
find /boot -name 'vmlinuz-*' -type f -exec cp {} /squashfs/vmlinuz \;
find /boot -name 'init*' -type f -exec cp {} /squashfs/initrd.img \;
Run Code Online (Sandbox Code Playgroud)

并在打包器中从 vm 下载工件:

{
  "type": "file",
  "direction": "download",
  "sources": [
    "/squashfs/vmlinuz"
  ],
  "destination": "output/{{user `name`}}-squashfs/{{user `name`}}.vmlinuz"
},
{
  "type": "file",
  "direction": "download",
  "sources": [
    "/squashfs/initrd.img"
  ],
  "destination": "output/{{user `name`}}-squashfs/{{user `name`}}.initrd"
},
{
  "type": "file",
  "direction": "download",
  "sources": [
    "/squashfs/filesystem.squashfs"
  ],
  "destination": "output/{{user `name`}}-squashfs/{{user `name`}}.squashfs"
}
Run Code Online (Sandbox Code Playgroud)