mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 00:32:09 -04:00
Merge pull request #9570 from hashicorp/azr-more-examples
HCL2: More examples for vsphere & vmware ( esxi )
This commit is contained in:
commit
21287fee58
29 changed files with 226 additions and 0 deletions
42
examples/hcl/linux/build.alpine.pkr.hcl
Normal file
42
examples/hcl/linux/build.alpine.pkr.hcl
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
build {
|
||||
name = "alpine"
|
||||
description = <<EOF
|
||||
This build creates alpine images for versions :
|
||||
* v3.12
|
||||
For the following builers :
|
||||
* virtualbox-iso
|
||||
EOF
|
||||
|
||||
// the common fields of the source blocks are defined in the
|
||||
// source.builder-type.pkr.hcl files, here we only set the fields specific to
|
||||
// the different versions of ubuntu.
|
||||
source "source.virtualbox-iso.base-alpine-amd64" {
|
||||
name = "3.12"
|
||||
iso_url = local.iso_url_alpine_312
|
||||
iso_checksum = "file:${local.iso_checksum_url_alpine_312}"
|
||||
output_directory = "virtualbox_iso_alpine_312_amd64"
|
||||
boot_command = local.alpine_312_floppy_boot_command
|
||||
boot_wait = "10s"
|
||||
}
|
||||
|
||||
source "source.vsphere-iso.base-alpine-amd64" {
|
||||
name = "3.12"
|
||||
vm_name = "alpine-3.12"
|
||||
iso_url = local.iso_url_alpine_312
|
||||
iso_checksum = "file:${local.iso_checksum_url_alpine_312}"
|
||||
boot_command = local.alpine_312_floppy_boot_command_vsphere
|
||||
boot_wait = "10s"
|
||||
}
|
||||
|
||||
source "source.vmware-iso.esxi-base-alpine-amd64" {
|
||||
name = "3.12-from-esxi"
|
||||
iso_url = local.iso_url_alpine_312
|
||||
iso_checksum = "file:${local.iso_checksum_url_alpine_312}"
|
||||
boot_command = local.alpine_312_floppy_boot_command_vsphere
|
||||
}
|
||||
|
||||
provisioner "shell" {
|
||||
inline = ["echo hi"]
|
||||
}
|
||||
}
|
||||
15
examples/hcl/linux/etc/http/alpine-answers
Normal file
15
examples/hcl/linux/etc/http/alpine-answers
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
KEYMAPOPTS="us us"
|
||||
HOSTNAMEOPTS="-n alpine"
|
||||
INTERFACESOPTS="auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
hostname alpine
|
||||
"
|
||||
TIMEZONEOPTS="-z UTC"
|
||||
PROXYOPTS="none"
|
||||
APKREPOSOPTS="http://mirrors.dotsrc.org/alpine/v3.8/main"
|
||||
SSHDOPTS="-c openssh"
|
||||
NTPOPTS="-c none"
|
||||
DISKOPTS="-m sys /dev/sda"
|
||||
21
examples/hcl/linux/etc/http/alpine-setup.sh
Normal file
21
examples/hcl/linux/etc/http/alpine-setup.sh
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
apk add libressl
|
||||
apk add open-vm-tools
|
||||
rc-update add open-vm-tools
|
||||
/etc/init.d/open-vm-tools start
|
||||
|
||||
cat >/usr/local/bin/shutdown <<EOF
|
||||
#!/bin/sh
|
||||
poweroff
|
||||
EOF
|
||||
chmod +x /usr/local/bin/shutdown
|
||||
|
||||
sed -i "/#PermitRootLogin/c\PermitRootLogin yes" /etc/ssh/sshd_config
|
||||
sed -i "/#PasswordAuthentication/c\PasswordAuthentication yes" /etc/ssh/sshd_config
|
||||
mkdir ~/.ssh
|
||||
# copy ssy key ?
|
||||
|
||||
/etc/init.d/sshd restart
|
||||
22
examples/hcl/linux/etc/http/alpine-vsphere-answers
Normal file
22
examples/hcl/linux/etc/http/alpine-vsphere-answers
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
KEYMAPOPTS="us us"
|
||||
HOSTNAMEOPTS="-n alpine"
|
||||
INTERFACESOPTS="auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet static
|
||||
address 147.75.201.6
|
||||
netmask 255.255.255.248
|
||||
network 147.75.201.0
|
||||
broadcast 147.75.201.7
|
||||
gateway 147.75.201.1
|
||||
"
|
||||
DNSOPTS="-d example.com 8.8.8.8"
|
||||
TIMEZONEOPTS="-z UTC"
|
||||
PROXYOPTS="none"
|
||||
APKREPOSOPTS="http://dl-cdn.alpinelinux.org/alpine/v3.12/main
|
||||
http://dl-cdn.alpinelinux.org/alpine/v3.8/main
|
||||
"
|
||||
SSHDOPTS="-c openssh"
|
||||
NTPOPTS="-c none"
|
||||
DISKOPTS="-m sys /dev/sda"
|
||||
|
|
@ -22,3 +22,28 @@ source "vmware-iso" "esxi-base-ubuntu-amd64" {
|
|||
remote_datastore = var.datastore
|
||||
remote_private_key_file = var.remote_private_key_file_path
|
||||
}
|
||||
|
||||
source "vmware-iso" "esxi-base-alpine-amd64" {
|
||||
headless = var.headless
|
||||
boot_wait = "10s"
|
||||
guest_os_type = "otherLinux64Guest"
|
||||
floppy_files = local.floppy_files_alpine_vsphere
|
||||
ssh_port = 22
|
||||
ssh_timeout = "10000s"
|
||||
ssh_username = "root"
|
||||
ssh_password = var.alpine_password
|
||||
tools_upload_flavor = "linux"
|
||||
shutdown_command = "poweroff"
|
||||
vmx_data = {
|
||||
"cpuid.coresPerSocket" = "1"
|
||||
"ethernet0.pciSlotNumber" = "32"
|
||||
}
|
||||
vmx_remove_ethernet_interfaces = true
|
||||
|
||||
remote_type = "esx5"
|
||||
remote_host = var.esxi_host
|
||||
remote_username = var.esxi_user
|
||||
remote_password = var.esxi_password
|
||||
remote_datastore = var.datastore
|
||||
remote_private_key_file = var.remote_private_key_file_path
|
||||
}
|
||||
|
|
@ -12,3 +12,15 @@ source "virtualbox-iso" "base-ubuntu-amd64" {
|
|||
guest_additions_path = "VBoxGuestAdditions_{{.Version}}.iso"
|
||||
guest_additions_url = var.guest_additions_url
|
||||
}
|
||||
|
||||
source "virtualbox-iso" "base-alpine-amd64" {
|
||||
headless = var.headless
|
||||
guest_os_type = "Linux26_64"
|
||||
http_directory = local.http_directory
|
||||
hard_drive_interface = "sata"
|
||||
ssh_username = "root"
|
||||
ssh_password = var.alpine_password
|
||||
ssh_wait_timeout = "60m"
|
||||
shutdown_command = "poweroff"
|
||||
floppy_files = local.floppy_files_alpine
|
||||
}
|
||||
|
|
@ -80,3 +80,36 @@ source "vsphere-iso" "base-ubuntu-amd64" {
|
|||
"<enter>"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
source "vsphere-iso" "base-alpine-amd64" {
|
||||
vcenter_server = var.vcenter_endpoint
|
||||
username = var.vcenter_user
|
||||
password = var.vcenter_password
|
||||
host = var.esxi_host
|
||||
insecure_connection = true
|
||||
|
||||
datacenter = var.datacenter_name
|
||||
datastore = "datastore1"
|
||||
|
||||
ssh_username = "root"
|
||||
ssh_password = var.alpine_password
|
||||
|
||||
CPUs = 1
|
||||
RAM = 512 * 2
|
||||
RAM_reserve_all = true
|
||||
|
||||
guest_os_type = "otherLinux64Guest"
|
||||
|
||||
floppy_files = local.floppy_files_alpine_vsphere
|
||||
|
||||
network_adapters {
|
||||
network = "VM Network"
|
||||
network_card = "vmxnet3"
|
||||
}
|
||||
|
||||
storage {
|
||||
disk_size = 32768
|
||||
disk_thin_provisioned = true
|
||||
}
|
||||
}
|
||||
56
examples/hcl/linux/variables.alpine.pkr.hcl
Normal file
56
examples/hcl/linux/variables.alpine.pkr.hcl
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
variable "alpine_password" {
|
||||
type = string
|
||||
default = "alpine"
|
||||
}
|
||||
|
||||
locals {
|
||||
iso_url_alpine_312 = "http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.0-x86_64.iso"
|
||||
iso_checksum_url_alpine_312 = "http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.0-x86_64.iso.sha256"
|
||||
floppy_files_alpine = [
|
||||
"${local.http_directory}/alpine-answers",
|
||||
"${local.http_directory}/alpine-setup.sh"
|
||||
]
|
||||
|
||||
alpine_312_floppy_boot_command = [
|
||||
"root<enter><wait>",
|
||||
"mount -t vfat /dev/fd0 /media/floppy<enter><wait>",
|
||||
"setup-alpine -f /media/floppy/alpine-answers<enter>",
|
||||
"<wait5>",
|
||||
"${var.alpine_password}<enter>",
|
||||
"${var.alpine_password}<enter>",
|
||||
"<wait5>",
|
||||
"y<enter>",
|
||||
"<wait40s>",
|
||||
"reboot<enter>",
|
||||
"<wait20s>",
|
||||
"root<enter>",
|
||||
"${var.alpine_password}<enter><wait>",
|
||||
"mount -t vfat /dev/fd0 /media/floppy<enter><wait>",
|
||||
"/media/floppy/alpine-setup.sh<enter>",
|
||||
]
|
||||
|
||||
floppy_files_alpine_vsphere = [
|
||||
"${local.http_directory}/alpine-vsphere-answers",
|
||||
"${local.http_directory}/alpine-setup.sh"
|
||||
]
|
||||
|
||||
alpine_312_floppy_boot_command_vsphere = [
|
||||
"root<enter><wait1s>",
|
||||
"mount -t vfat /dev/fd0 /media/floppy<enter><wait1s>",
|
||||
"setup-alpine -f /media/floppy/alpine-vsphere-answers<enter><wait3s>",
|
||||
"${var.alpine_password}<enter>",
|
||||
"${var.alpine_password}<enter>",
|
||||
"<wait6s>",
|
||||
"y<enter>",
|
||||
"<wait12s>",
|
||||
"reboot<enter>",
|
||||
"<wait12s>",
|
||||
"root<enter>",
|
||||
"${var.alpine_password}<enter><wait>",
|
||||
"mount -t vfat /dev/fd0 /media/floppy<enter><wait>",
|
||||
"/media/floppy/alpine-setup.sh<enter>",
|
||||
"<wait55s>",
|
||||
]
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue