Merge pull request #7 from 4censord/add-more-examples
Add more examples
This commit is contained in:
commit
77801d5798
@ -1,22 +1,27 @@
|
||||
## 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. At the time of this writing there are examples for the latest Ubuntu (20.04) and Centos (8.3) releases. Please open an issue if you'd like to see an example for another distro.
|
||||
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 this example you will need to perform the following steps:
|
||||
1. Export the `XAPI_HOST`, `XAPI_USERNAME` and `XAPI_PASSWORD` environment variables to the current shell. Note: The `XAPI_HOST` must be the resource pool primary.
|
||||
2. Run the `packer build` command specifying the storage repositories to use for the ISO upload and for the VM created during the build.
|
||||
|
||||
In order to run the examples you will need to perform the following steps:
|
||||
1. Export those vars:
|
||||
```
|
||||
# Replace sr_name and sr_iso_name with your storage repositories names
|
||||
packer build -debug --var sr_name='Local storage' --var sr_iso_name=LocalISO examples/centos8.json
|
||||
|
||||
# Do the same variable replacement for the ubuntu example as well.
|
||||
packer build -debug --var sr_name='Local storage' --var sr_iso_name=LocalISO examples/ubuntu-2004.json
|
||||
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
|
||||
|
||||
@ -24,9 +29,8 @@ The Ubuntu example uses the [autoinstall tool](https://ubuntu.com/server/docs/in
|
||||
|
||||
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 example uses kickstart 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.
|
||||
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"]
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
{
|
||||
"variables": {
|
||||
"sr_name": "",
|
||||
"sr_iso_name": "",
|
||||
"remote_host": "{{env `XAPI_HOST`}}",
|
||||
"remote_username": "{{env `XAPI_USERNAME`}}",
|
||||
"remote_password": "{{env `XAPI_PASSWORD`}}"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "xenserver-iso",
|
||||
"sr_name": "{{user `sr_name`}}",
|
||||
"sr_iso_name": "{{user `sr_iso_name`}}",
|
||||
"remote_host": "{{user `remote_host`}}",
|
||||
"remote_username": "{{user `remote_username`}}",
|
||||
"remote_password": "{{user `remote_password`}}",
|
||||
"vm_memory": "4096",
|
||||
"boot_command": [
|
||||
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8.cfg<enter><wait>"
|
||||
],
|
||||
"boot_wait": "10s",
|
||||
"disk_size": 40960,
|
||||
"http_directory": "examples/http/centos8",
|
||||
"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",
|
||||
"iso_name": "CentOS-8.3.2011-x86_64-boot.iso",
|
||||
"tools_iso_name": "guest-tools.iso",
|
||||
"vm_other_config": {
|
||||
"conversionvm":"true"
|
||||
},
|
||||
"output_directory": "packer-centos-8.3-x86_64-xenserver",
|
||||
"ssh_username": "vagrant",
|
||||
"ssh_password": "vagrant",
|
||||
"ssh_wait_timeout": "10000s",
|
||||
"ssh_agent_auth": false,
|
||||
"vm_name": "packer-centos-8.3-x86_64-{{isotime}}",
|
||||
"vm_description": "Build time: {{isotime}}",
|
||||
"keep_vm": "always"
|
||||
}
|
||||
]
|
||||
}
|
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
|
||||
|
@ -1,74 +0,0 @@
|
||||
install
|
||||
# TODO: Figure out why cdrom does not work
|
||||
# cdrom
|
||||
# TODO: parameterize this from the packer config file
|
||||
url --url="http://mirror.centos.org/centos/8.3.2011/BaseOS/x86_64/os/"
|
||||
lang en_US.UTF-8
|
||||
keyboard us
|
||||
network --bootproto=dhcp
|
||||
rootpw vagrant
|
||||
firewall --disabled
|
||||
selinux --permissive
|
||||
timezone UTC
|
||||
bootloader --location=mbr
|
||||
text
|
||||
skipx
|
||||
zerombr
|
||||
clearpart --all --initlabel
|
||||
autopart
|
||||
auth --enableshadow --passalgo=sha512 --kickstart
|
||||
firstboot --disabled
|
||||
eula --agreed
|
||||
services --enabled=NetworkManager,sshd
|
||||
user --name=vagrant --plaintext --password=vagrant --groups=wheel
|
||||
reboot
|
||||
|
||||
%packages --ignoremissing --excludedocs
|
||||
openssh-clients
|
||||
sudo
|
||||
net-tools
|
||||
wget
|
||||
curl
|
||||
|
||||
# unnecessary firmware
|
||||
-aic94xx-firmware
|
||||
-atmel-firmware
|
||||
-b43-openfwwf
|
||||
-bfa-firmware
|
||||
-ipw2100-firmware
|
||||
-ipw2200-firmware
|
||||
-ivtv-firmware
|
||||
-iwl100-firmware
|
||||
-iwl1000-firmware
|
||||
-iwl3945-firmware
|
||||
-iwl4965-firmware
|
||||
-iwl5000-firmware
|
||||
-iwl5150-firmware
|
||||
-iwl6000-firmware
|
||||
-iwl6000g2a-firmware
|
||||
-iwl6050-firmware
|
||||
-libertas-usb8388-firmware
|
||||
-ql2100-firmware
|
||||
-ql2200-firmware
|
||||
-ql23xx-firmware
|
||||
-ql2400-firmware
|
||||
-ql2500-firmware
|
||||
-rt61pci-firmware
|
||||
-rt73usb-firmware
|
||||
-xorg-x11-drv-ati-firmware
|
||||
-zd1211-firmware
|
||||
%end
|
||||
|
||||
%post
|
||||
yum update -y
|
||||
|
||||
# update root certs
|
||||
wget -O/etc/pki/tls/certs/ca-bundle.crt http://curl.haxx.se/ca/cacert.pem
|
||||
|
||||
# sudo
|
||||
yum install -y sudo
|
||||
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
|
||||
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
|
||||
|
||||
yum clean all
|
||||
%end
|
@ -1,44 +0,0 @@
|
||||
{
|
||||
"variables": {
|
||||
"sr_name": "",
|
||||
"sr_iso_name": "",
|
||||
"remote_host": "{{env `XAPI_HOST`}}",
|
||||
"remote_username": "{{env `XAPI_USERNAME`}}",
|
||||
"remote_password": "{{env `XAPI_PASSWORD`}}"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "xenserver-iso",
|
||||
"sr_name": "{{user `sr_name`}}",
|
||||
"sr_iso_name": "{{user `sr_iso_name`}}",
|
||||
"remote_host": "{{user `remote_host`}}",
|
||||
"remote_username": "{{user `remote_username`}}",
|
||||
"remote_password": "{{user `remote_password`}}",
|
||||
"tools_iso_name": "guest-tools.iso",
|
||||
"boot_command": [
|
||||
"<esc><f6> autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<enter><wait>",
|
||||
"<f6><wait><esc><wait> autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<enter><wait>"
|
||||
],
|
||||
"boot_wait": "10s",
|
||||
"disk_size": 10960,
|
||||
"http_directory": "examples/http/ubuntu-2004",
|
||||
"iso_checksum": "443511f6bf12402c12503733059269a2e10dec602916c0a75263e5d990f6bb93",
|
||||
"iso_checksum_type": "sha256",
|
||||
"iso_url": "http://releases.ubuntu.com/20.04/ubuntu-20.04.1-live-server-amd64.iso",
|
||||
"iso_name": "ubuntu-20.04.1-live-server-amd64.iso",
|
||||
"vm_other_config": {
|
||||
"conversionvm":"true"
|
||||
},
|
||||
"output_directory": "packer-ubuntu-2004-x86_64-xenserver",
|
||||
"ssh_username": "testuser",
|
||||
"ssh_password": "ubuntu",
|
||||
"ssh_wait_timeout": "60000s",
|
||||
"ssh_timeout": "60000s",
|
||||
"vm_name": "packer-ubuntu-2004-x86_64 {{isotime}}",
|
||||
"vm_description": "Build time: {{isotime}}",
|
||||
"vm_memory": "4096",
|
||||
"keep_vm": "always",
|
||||
"ssh_handshake_attempts": "10000"
|
||||
}
|
||||
]
|
||||
}
|
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 = "d1f2bf834bbe9bb43faf16f9be992a6f3935e65be0edece1dee2aa6eb1767423"
|
||||
iso_checksum_type = "sha256"
|
||||
iso_url = "http://releases.ubuntu.com/20.04/ubuntu-20.04.2-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
|
||||
|
||||
vm_name = "packer-ubuntu-2004-${local.timestamp}"
|
||||
vm_description = "Build started: ${local.timestamp}"
|
||||
vm_memory = 4096
|
||||
disk_size = 20000
|
||||
|
||||
http_directory = "examples/http/ubuntu-2004"
|
||||
boot_command = [
|
||||
"<esc><f6> autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<enter><wait>",
|
||||
"<f6><wait><esc><wait> autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<enter><wait>"
|
||||
]
|
||||
boot_wait = "10s"
|
||||
|
||||
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"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user