1 Star 0 Fork 1

wushifeng / devops

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
centos7.pkr.hcl 7.41 KB
一键复制 编辑 原始数据 按行查看 历史
wushifeng 提交于 2021-03-03 14:37 . packer的文件使用注释
variable "headless" {
type = string
description = "是否显示客户端的软件界面,显示的话,可以方便跟踪"
default = "false"
}
variable "cleanup_build_tools" {
type = string
default = "false"
}
#虚拟机的一些配置设定
variable "vm_name" {
type = string
default = "centos7"
}
variable "cpus" {
type = string
default = "1"
}
variable "memory" {
type = string
default = "512"
}
variable "disk_size" {
type = string
default = "65536"
}
variable "desktop" {
type = string
description = "是否安装桌面系统"
default = "false"
}
variable "http_directory" {
type = string
description = "ks的服务地址"
default = "kickstart/centos7"
}
variable "http_proxy" {
type = string
default = "${env("http_proxy")}"
}
variable "https_proxy" {
type = string
default = "${env("https_proxy")}"
}
variable "no_proxy" {
type = string
default = "${env("no_proxy")}"
}
variable "ftp_proxy" {
type = string
default = "${env("ftp_proxy")}"
}
variable "rsync_proxy" {
type = string
default = "${env("rsync_proxy")}"
}
##
variable "install_vagrant_key" {
type = string
default = "true"
}
###iso镜像的设置
variable "iso_checksum" {
type = string
default = "9a2c47d97b9975452f7d582264e9fc16d108ed8252ac6816239a3b58cef5c53d"
}
variable "iso_checksum_type" {
type = string
default = "sha256"
}
# variable "iso_name" {
# type = string
# default = "CentOS-7-x86_64-DVD-1708.iso"
# }
# variable "iso_path" {
# type = string
# default = "iso"
# }
#简化,只要有一个能找到的就行,本地文件或者URL
variable "iso_url" {
type = string
default = "CentOS-7-x86_64-Minimal-1908.iso" #"http://mirrors.kernel.org/centos/7.4.1708/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso"
}
variable "kickstart" {
type = string
default = "ks.cfg"
}
variable "shutdown_command" {
type = string
default = "echo 'vagrant'|sudo -S shutdown -P now"
}
#这个和os的kickstart中设置的用户一致
variable "ssh_password" {
type = string
default = "vagrant"
}
variable "ssh_username" {
type = string
default = "vagrant"
}
variable "update" {
type = string
default = "false"
}
variable "vagrantfile_template" {
type = string
}
variable "version" {
type = string
default = "0.0.99"
}
variable "virtualbox_guest_os_type" {
type = string
default = "centos7_64"
}
variable "virtualbox_nictype" {
type = string
default = "virtio"
}
variable "virtualbox_paravirtprovider" {
type = string
default = "default"
}
#在vsphere运行是会提示兼容信息,最好安要求设置
#https://code.vmware.com/apis/358/doc/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html
variable "vmware_guest_os_type" {
type = string
#default = "centos7_64Guest" #按照vcenter API赋值还不行,无法正常启动,估计设计时有去缺陷
default = "centos-64"
}
source "virtualbox-iso" "virtualbox" {
http_directory = "${var.http_directory}"
boot_command = ["<up><wait><tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/${var.kickstart}<enter>"]
disk_size = "${var.disk_size}"
guest_additions_path = "VBoxGuestAdditions_{{ .Version }}.iso"
guest_os_type = "${var.virtualbox_guest_os_type}"
hard_drive_interface = "sata"
headless = "${var.headless}"
iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum}"
#iso_urls = ["${var.iso_path}/${var.iso_name}", "${var.iso_url}"]
iso_urls = ["${var.iso_url}"]
output_directory = "output-${var.vm_name}-virtualbox-iso"
shutdown_command = "${var.shutdown_command}"
ssh_password = "${var.ssh_password}"
ssh_timeout = "10000s"
ssh_username = "${var.ssh_username}"
vboxmanage = [["modifyvm", "{{ .Name }}", "--memory", "${var.memory}"], ["modifyvm", "{{ .Name }}", "--cpus", "${var.cpus}"], ["modifyvm", "{{ .Name }}", "--paravirtprovider", "${var.virtualbox_paravirtprovider}"], ["modifyvm", "{{ .Name }}", "--nictype1", "${var.virtualbox_nictype}"]]
virtualbox_version_file = ".vbox_version"
vm_name = "${var.vm_name}"
}
source "vmware-iso" "vmware" {
boot_command = ["<up><wait><tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/${var.kickstart}<enter>"]
disk_size = "${var.disk_size}"
guest_os_type = "${var.vmware_guest_os_type}"
headless = "${var.headless}"
http_directory = "${var.http_directory}"
iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum}"
#iso_urls = ["${var.iso_path}/${var.iso_name}", "${var.iso_url}"]
iso_urls = ["${var.iso_url}"]
output_directory = "output-${var.vm_name}-vmware-iso"
shutdown_command = "${var.shutdown_command}"
ssh_password = "${var.ssh_password}"
ssh_timeout = "10000s"
ssh_username = "${var.ssh_username}"
tools_upload_flavor = "linux"
vm_name = "${var.vm_name}"
vmx_data = {
"cpuid.coresPerSocket" = "1"
#根据提示不设置了 Warning: Your vmx data contains the following variable(s), which Packer normally sets when it generates its own default vmx template. This may cause your build to fail or behave unpredictably: numvcpus, memsize
# memsize = "${var.memory}"
# numvcpus = "${var.cpus}"
}
vmx_remove_ethernet_interfaces = true
#使用有dhcp的这个网络,这样kickstart就可以找到了
network = "vmnet8"
boot_wait = "5s"
boot_key_interval = "1ms"
}
build {
sources = [
"source.virtualbox-iso.virtualbox",
"source.vmware-iso.vmware"
]
provisioner "shell" {
environment_vars = [
"CLEANUP_BUILD_TOOLS=${var.cleanup_build_tools}",
"DESKTOP=${var.desktop}",
"UPDATE=${var.update}",
"INSTALL_VAGRANT_KEY=${var.install_vagrant_key}",
"SSH_USERNAME=${var.ssh_username}",
"SSH_PASSWORD=${var.ssh_password}",
"http_proxy=${var.http_proxy}",
"https_proxy=${var.https_proxy}",
"ftp_proxy=${var.ftp_proxy}",
"rsync_proxy=${var.rsync_proxy}",
"no_proxy=${var.no_proxy}"
]
execute_command = "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'"
expect_disconnect = "true"
scripts = ["script/update.sh"]
}
provisioner "shell" {
environment_vars = [
"CLEANUP_BUILD_TOOLS=${var.cleanup_build_tools}",
"DESKTOP=${var.desktop}",
"UPDATE=${var.update}",
"INSTALL_VAGRANT_KEY=${var.install_vagrant_key}",
"SSH_USERNAME=${var.ssh_username}",
"SSH_PASSWORD=${var.ssh_password}",
"http_proxy=${var.http_proxy}",
"https_proxy=${var.https_proxy}",
"ftp_proxy=${var.ftp_proxy}",
"rsync_proxy=${var.rsync_proxy}",
"no_proxy=${var.no_proxy}"
]
execute_command = "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'"
scripts = [
"script/fix-slow-dns.sh",
"script/sshd.sh",
"script/vagrant.sh",
"script/desktop.sh",
"script/vmware.sh",
"script/virtualbox.sh",
"script/motd.sh",
"custom-script.sh",
"script/cleanup.sh"
]
}
post-processor "vagrant" {
#虚拟机文件做完box后不删除
keep_input_artifact = true
output = "box/{{.Provider}}/${var.vm_name}-${var.version}.box"
vagrantfile_template = "${var.vagrantfile_template}"
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/wushifeng/devops.git
git@gitee.com:wushifeng/devops.git
wushifeng
devops
devops
master

搜索帮助