packer demo

ks  应答文件demo

 

复制代码
install
text
reboot
lang en_US.UTF-8
keyboard us
timezone --utc Etc/UTC
rootpw --plaintext 'kangwen12#$'
zerombr
autopart  --type=plain --fstype=ext4
bootloader --location=mbr
clearpart --all --initlabel 


%packages
@core
%end

%post --erroronfail
sed -i 's/PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
echo 'PermitRootLogin yes' >>  /etc/ssh/sshd_config
echo 'PasswordAuthentication yes'  >> /etc/ssh/sshd_config
%end
复制代码

 

基于ISO 安装的一个 packer 配置文件

复制代码
{
  "builders": [
    {
      "type": "qemu",
      "qemu_binary": "qemu-kvm",
      "iso_url": "/disk9/jinkangkang/CentOS-7-x86_64-Minimal-2009.iso",
      "iso_checksum": "md5:a4711c4fa6a1fb32bd555fae8d885b12",
      "output_directory": "tmpkw",
      "shutdown_command": "sudo -S shutdown -P now",
      "disk_size": "5000M",
      "format": "qcow2",
      "accelerator": "kvm",
      "http_directory": "ks",
      "ssh_username": "root",
      "ssh_password": "kangwen12#$",
      "ssh_timeout": "20m",
      "vm_name": "tdhtest",
      "net_device": "virtio-net",
      "disk_interface": "virtio",
      "boot_wait": "10s",
      "vnc_bind_address": "0.0.0.0",
      "boot_command": [
        "<tab> inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
      ],
      "qemuargs": [
        [
          "-display",
          "none"
        ]
      ]
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "scripts": [
        "/disk9/jinkangkang/kw/test.sh"
      ]
    }
  ]
}
复制代码

 

 基与一个原有镜像构建的模板

复制代码
{
  "builders": [
    {
      "type": "qemu",
      "qemu_binary": "qemu-kvm",
      "iso_url": "/disk9/jinkangkang/CentOS-7-x86_64-Minimal-2009.iso",
      "iso_checksum": "md5:a4711c4fa6a1fb32bd555fae8d885b12",
      "shutdown_command": "sudo -S shutdown -P now",
      "accelerator": "kvm",
      "http_directory": "ks",
      "ssh_username": "root",
      "ssh_password": "kangwen12#$",
      "ssh_timeout": "20m",
      "vm_name": "kw2",
      "net_device": "virtio-net",
      "disk_interface": "virtio",
      "boot_wait": "10s",
      "vnc_bind_address": "0.0.0.0",
      "qemuargs": [
        [
          "-display",
          "none"
        ],
        [ "-drive", "file=/disk9/jinkangkang/kw/kwbase.qcow2,if=none,id=drive-virtio-disk0,format=qcow2"
        ],
        [ "-device", "virtio-blk-pci,scsi=off,num-queues=1,x-data-plane=off,vectors=2,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1"
        ]
      ]
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "scripts": [
        "/disk9/jinkangkang/kw/test2.sh"
      ]
    }
  ]
}
复制代码

上面的 /disk9/jinkangkang/kw/kwbase.qcow2 就是原有镜像,"ssh_password": "kangwen12#$", 是镜像的密码

 

构建命令:

sudo ./packer build packer.json

sudo PACKER_LOG=1 ./packer build packer.json  (日志更详细)

posted on   思此狂  阅读(101)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示