Initial commit
This commit is contained in:
36
examples/README.md
Normal file
36
examples/README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
## Examples
|
||||
|
||||
In order for new users to get up and running with the packer builder, a few examples of building a machine image with popular distros have been created.
|
||||
|
||||
In order to see an exhaustive list of configuration options for the packer builder please see the [following documentation](../docs/builders/xenserver-iso.html.markdown). This doc will focus on the details relevant to the particular distro.
|
||||
|
||||
### Running the examples
|
||||
|
||||
In order to run the examples you will need to perform the following steps:
|
||||
1. Export those vars:
|
||||
```
|
||||
PKR_VAR_remote_host
|
||||
PKR_VAR_remote_password
|
||||
PKR_VAR_remote_username
|
||||
PKR_VAR_sr_name
|
||||
PKR_VAR_sr_iso_name
|
||||
```
|
||||
`PKR_VAR_remote_host` must be the resource pool primary, aka the master.
|
||||
|
||||
2. Run `packer init path/to/defenition.pkr.hcl` to download the xenserver plugin
|
||||
|
||||
2. Run `packer build path/to/defenition.pkr.hcl`
|
||||
so for example:
|
||||
`packer build examples/centos/centos8-netinstall.pkr.hcl`
|
||||
|
||||
### Ubuntu
|
||||
|
||||
The Ubuntu example uses the [autoinstall tool](https://ubuntu.com/server/docs/install/autoinstallhttps://ubuntu.com/server/docs/install/autoinstall) to configure the VM template. Please see the [autoinstall docs](https://ubuntu.com/server/docs/install/autoinstall-reference) for an exhaustive list of what is supported.
|
||||
|
||||
Packer will create a http server to serve the files as specified from the `http_directory` specified in the builder configuration. This is where the [user-data](http/ubuntu-2004/user-data) and [meta-data](http/ubuntu-2004/meta-data) for autoinstall must be present.
|
||||
|
||||
### Centos
|
||||
|
||||
The Centos examples use kickstart files to configure the VM template. Please see the [kickstart documentation](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/sect-kickstart-syntax) for the options that are supported.
|
||||
|
||||
Packer will create a http server to serve the files as specified from the `http_directory` specified in the builder configuration. This is where the [kickstart config](http/centos8/ks-centos8.cfg) file must be present.
|
81
examples/centos/centos8-local.pkr.hcl
Normal file
81
examples/centos/centos8-local.pkr.hcl
Normal file
@@ -0,0 +1,81 @@
|
||||
packer {
|
||||
required_plugins {
|
||||
xenserver= {
|
||||
version = ">= v0.3.2"
|
||||
source = "github.com/ddelnano/xenserver"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "remote_host" {
|
||||
type = string
|
||||
description = "The ip or fqdn of your XenServer. This will be pulled from the env var 'PKR_VAR_remote_host'"
|
||||
sensitive = true
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "remote_password" {
|
||||
type = string
|
||||
description = "The password used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_remote_password'"
|
||||
sensitive = true
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "remote_username" {
|
||||
type = string
|
||||
description = "The username used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_remote_username'"
|
||||
sensitive = true
|
||||
default = null
|
||||
|
||||
}
|
||||
|
||||
variable "sr_iso_name" {
|
||||
type = string
|
||||
default = ""
|
||||
description = "The ISO-SR to packer will use"
|
||||
|
||||
}
|
||||
|
||||
variable "sr_name" {
|
||||
type = string
|
||||
default = ""
|
||||
description = "The name of the SR to packer will use"
|
||||
}
|
||||
|
||||
locals {
|
||||
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
|
||||
}
|
||||
|
||||
source "xenserver-iso" "centos8-local" {
|
||||
iso_checksum = "aaf9d4b3071c16dbbda01dfe06085e5d0fdac76df323e3bbe87cce4318052247"
|
||||
iso_checksum_type = "sha1"
|
||||
iso_url = "http://mirrors.ocf.berkeley.edu/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-dvd1.iso"
|
||||
|
||||
sr_iso_name = var.sr_iso_name
|
||||
sr_name = var.sr_name
|
||||
tools_iso_name = "guest-tools.iso"
|
||||
|
||||
remote_host = var.remote_host
|
||||
remote_password = var.remote_password
|
||||
remote_username = var.remote_username
|
||||
|
||||
vm_name = "packer-centos8-local-${local.timestamp}"
|
||||
vm_description = "Build started: ${local.timestamp}\n This was installed from the dvd"
|
||||
vm_memory = 4096
|
||||
disk_size = 4096
|
||||
|
||||
http_directory = "examples/http/centos8"
|
||||
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-local.cfg<enter><wait>"]
|
||||
boot_wait = "10s"
|
||||
|
||||
ssh_username = "root"
|
||||
ssh_password = "centos"
|
||||
ssh_wait_timeout = "10000s"
|
||||
|
||||
output_directory = "packer-centos8-local"
|
||||
keep_vm = "always"
|
||||
}
|
||||
|
||||
build {
|
||||
sources = ["xenserver-iso.centos8-local"]
|
||||
}
|
81
examples/centos/centos8-netinstall.pkr.hcl
Normal file
81
examples/centos/centos8-netinstall.pkr.hcl
Normal file
@@ -0,0 +1,81 @@
|
||||
packer {
|
||||
required_plugins {
|
||||
xenserver= {
|
||||
version = ">= v0.3.2"
|
||||
source = "github.com/ddelnano/xenserver"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "remote_host" {
|
||||
type = string
|
||||
description = "The ip or fqdn of your XenServer. This will be pulled from the env var 'PKR_VAR_remote_host'"
|
||||
sensitive = true
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "remote_password" {
|
||||
type = string
|
||||
description = "The password used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_remote_password'"
|
||||
sensitive = true
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "remote_username" {
|
||||
type = string
|
||||
description = "The username used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_remote_username'"
|
||||
sensitive = true
|
||||
default = null
|
||||
|
||||
}
|
||||
|
||||
variable "sr_iso_name" {
|
||||
type = string
|
||||
default = ""
|
||||
description = "The ISO-SR to packer will use"
|
||||
|
||||
}
|
||||
|
||||
variable "sr_name" {
|
||||
type = string
|
||||
default = ""
|
||||
description = "The name of the SR to packer will use"
|
||||
}
|
||||
|
||||
locals {
|
||||
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
|
||||
}
|
||||
|
||||
source "xenserver-iso" "centos8-netinstall" {
|
||||
iso_checksum = "07a8e59c42cc086ec4c49bdce4fae5a17b077dea"
|
||||
iso_checksum_type = "sha1"
|
||||
iso_url = "http://mirrors.ocf.berkeley.edu/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-boot.iso"
|
||||
|
||||
sr_iso_name = var.sr_iso_name
|
||||
sr_name = var.sr_name
|
||||
tools_iso_name = "guest-tools.iso"
|
||||
|
||||
remote_host = var.remote_host
|
||||
remote_password = var.remote_password
|
||||
remote_username = var.remote_username
|
||||
|
||||
vm_name = "packer-centos8-netinstall-${local.timestamp}"
|
||||
vm_description = "Build started: ${local.timestamp}\n This was installed with an external repository"
|
||||
vm_memory = 4096
|
||||
disk_size = 4096
|
||||
|
||||
http_directory = "examples/http/centos8"
|
||||
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-netinstall.cfg<enter><wait>"]
|
||||
boot_wait = "10s"
|
||||
|
||||
ssh_username = "root"
|
||||
ssh_password = "centos"
|
||||
ssh_wait_timeout = "10000s"
|
||||
|
||||
output_directory = "packer-centos8-netinstall"
|
||||
keep_vm = "always"
|
||||
}
|
||||
|
||||
build {
|
||||
sources = ["xenserver-iso.centos8-netinstall"]
|
||||
}
|
47
examples/http/centos8/ks-centos8-local.cfg
Normal file
47
examples/http/centos8/ks-centos8-local.cfg
Normal file
@@ -0,0 +1,47 @@
|
||||
eula --agreed
|
||||
lang en-US.UTF-8
|
||||
keyboard --vckeymap='de' --xlayouts='de'
|
||||
timezone Europe/Berlin
|
||||
|
||||
cdrom
|
||||
|
||||
text
|
||||
skipx
|
||||
firstboot --disable
|
||||
|
||||
rootpw --plaintext centos
|
||||
|
||||
firewall --enabled --ssh
|
||||
selinux --enforcing
|
||||
|
||||
# Installation logging level
|
||||
logging --level=info
|
||||
|
||||
network --bootproto=dhcp --device=eth0 --onboot=on
|
||||
|
||||
# System bootloader configuration
|
||||
bootloader --location=mbr
|
||||
zerombr
|
||||
clearpart --all
|
||||
|
||||
# Disk partitioning information
|
||||
part / --asprimary --fstype="ext4" --size=1024 --grow
|
||||
|
||||
|
||||
%addon com_redhat_kdump --disable
|
||||
%end
|
||||
|
||||
%packages --ignoremissing --excludedocs
|
||||
openssh-clients
|
||||
sudo
|
||||
|
||||
# unnecessary firmware
|
||||
-aic94xx-firmware*
|
||||
-alsa-*
|
||||
-ivtv-*
|
||||
-iwl*firmware
|
||||
%end
|
||||
|
||||
# Reboot after installation
|
||||
reboot --eject
|
||||
|
46
examples/http/centos8/ks-centos8-netinstall.cfg
Normal file
46
examples/http/centos8/ks-centos8-netinstall.cfg
Normal file
@@ -0,0 +1,46 @@
|
||||
eula --agreed
|
||||
lang en-US.UTF-8
|
||||
keyboard --vckeymap='de' --xlayouts='de'
|
||||
timezone Europe/Berlin
|
||||
|
||||
text
|
||||
skipx
|
||||
firstboot --disable
|
||||
|
||||
url --url="http://mirror.centos.org/centos/8.3.2011/BaseOS/x86_64/os/"
|
||||
rootpw --plaintext centos
|
||||
|
||||
firewall --enabled --ssh
|
||||
selinux --enforcing
|
||||
|
||||
# Installation logging level
|
||||
logging --level=info
|
||||
|
||||
network --bootproto=dhcp --device=eth0 --onboot=on
|
||||
|
||||
# System bootloader configuration
|
||||
bootloader --location=mbr
|
||||
zerombr
|
||||
clearpart --all
|
||||
|
||||
# Disk partitioning information
|
||||
part / --asprimary --fstype="ext4" --size=1024 --grow
|
||||
|
||||
|
||||
%addon com_redhat_kdump --disable
|
||||
%end
|
||||
|
||||
%packages --ignoremissing --excludedocs
|
||||
openssh-clients
|
||||
sudo
|
||||
|
||||
# unnecessary firmware
|
||||
-aic94xx-firmware*
|
||||
-alsa-*
|
||||
-ivtv-*
|
||||
-iwl*firmware
|
||||
%end
|
||||
|
||||
# Reboot after installation
|
||||
reboot --eject
|
||||
|
0
examples/http/ubuntu-2004/meta-data
Normal file
0
examples/http/ubuntu-2004/meta-data
Normal file
22
examples/http/ubuntu-2004/user-data
Normal file
22
examples/http/ubuntu-2004/user-data
Normal file
@@ -0,0 +1,22 @@
|
||||
#cloud-config
|
||||
|
||||
# hack for cloud-init per:
|
||||
# https://github.com/leakespeake/packer/blob/3f3e361751b4be9326b66771d96f2519bc8f885e/builders/vmware/vsphere-iso/ubuntu-server-20-04/hcl2/http/ubuntu-server-subiquity/user-data
|
||||
runcmd:
|
||||
# to enable true auto-install for Ubuntu 20.04 with cloud-init nocloud (eliminates "Continue with autoinstall?" prompt)
|
||||
- [eval, 'echo $(cat /proc/cmdline) "autoinstall" > /root/cmdline']
|
||||
- [eval, 'mount -n --bind -o ro /root/cmdline /proc/cmdline']
|
||||
- [eval, 'snap restart subiquity.subiquity-service']
|
||||
|
||||
autoinstall:
|
||||
version: 1
|
||||
identity:
|
||||
hostname: ubuntu-server
|
||||
# This is the crypted pass of 'ubuntu'
|
||||
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
|
||||
username: testuser
|
||||
packages:
|
||||
- xe-guest-utilities
|
||||
ssh:
|
||||
install-server: yes
|
||||
allow-pw: yes
|
86
examples/ubuntu/ubuntu-2004.pkr.hcl
Normal file
86
examples/ubuntu/ubuntu-2004.pkr.hcl
Normal file
@@ -0,0 +1,86 @@
|
||||
packer {
|
||||
required_plugins {
|
||||
xenserver= {
|
||||
version = ">= v0.3.2"
|
||||
source = "github.com/ddelnano/xenserver"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "remote_host" {
|
||||
type = string
|
||||
description = "The ip or fqdn of your XenServer. This will be pulled from the env var 'PKR_VAR_XAPI_HOST'"
|
||||
sensitive = true
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "remote_password" {
|
||||
type = string
|
||||
description = "The password used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_XAPI_PASSWORD'"
|
||||
sensitive = true
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "remote_username" {
|
||||
type = string
|
||||
description = "The username used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_XAPI_USERNAME'"
|
||||
sensitive = true
|
||||
default = null
|
||||
|
||||
}
|
||||
|
||||
variable "sr_iso_name" {
|
||||
type = string
|
||||
default = ""
|
||||
description = "The ISO-SR to packer will use"
|
||||
|
||||
}
|
||||
|
||||
variable "sr_name" {
|
||||
type = string
|
||||
default = ""
|
||||
description = "The name of the SR to packer will use"
|
||||
}
|
||||
|
||||
locals {
|
||||
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
|
||||
}
|
||||
|
||||
|
||||
source "xenserver-iso" "ubuntu-2004" {
|
||||
iso_checksum = "5035be37a7e9abbdc09f0d257f3e33416c1a0fb322ba860d42d74aa75c3468d4"
|
||||
iso_checksum_type = "sha256"
|
||||
iso_url = "http://releases.ubuntu.com/20.04/ubuntu-20.04.5-live-server-amd64.iso"
|
||||
|
||||
sr_iso_name = var.sr_iso_name
|
||||
sr_name = var.sr_name
|
||||
tools_iso_name = "guest-tools.iso"
|
||||
|
||||
remote_host = var.remote_host
|
||||
remote_password = var.remote_password
|
||||
remote_username = var.remote_username
|
||||
|
||||
# Change this to match the ISO of ubuntu you are using in the iso_url variable
|
||||
clone_template = "Ubuntu Focal Fossa 20.04"
|
||||
vm_name = "packer-ubuntu-2004-${local.timestamp}"
|
||||
vm_description = "Build started: ${local.timestamp}"
|
||||
vm_memory = 4096
|
||||
disk_size = 20000
|
||||
|
||||
floppy_files = [
|
||||
"examples/http/ubuntu-2004/meta-data",
|
||||
"examples/http/ubuntu-2004/user-data",
|
||||
]
|
||||
|
||||
ssh_username = "testuser"
|
||||
ssh_password = "ubuntu"
|
||||
ssh_wait_timeout = "60000s"
|
||||
ssh_handshake_attempts = 10000
|
||||
|
||||
output_directory = "packer-ubuntu-2004-iso"
|
||||
keep_vm = "always"
|
||||
}
|
||||
|
||||
build {
|
||||
sources = ["xenserver-iso.ubuntu-2004"]
|
||||
}
|
Reference in New Issue
Block a user