Compare commits

...

8 Commits

Author SHA1 Message Date
Daniel Koschützki
23a046503d Updated examples/readme.md for the ubuntu example 2021-04-13 12:51:56 -07:00
Daniel Koschützki
acf35e4901 removed centos8 json example and kickstart 2021-04-13 12:51:53 -07:00
daniel
266dd9869d Added a commented example of a centos8 build 2021-04-13 12:51:37 -07:00
Daniel Koschützki
8325249f0a Moved some files around ind docs/ 2021-04-13 12:51:37 -07:00
daniel
8a700e8e42 Added a commented example of a centos8 build 2021-04-13 12:51:37 -07:00
daniel
207135c85e added local DVD install example 2021-04-13 12:51:37 -07:00
daniel
aa5a925245 updated examples/README.md to refekt current state 2021-04-13 12:51:37 -07:00
daniel
1696c6e02e added centos8-netinstall 2021-04-13 12:51:37 -07:00
11 changed files with 621 additions and 78 deletions

View File

@ -0,0 +1,127 @@
---
layout: "docs"
page_title: "XenServer-iso Commented Example"
description: |-
This is a Commented example for how to use the xenserver-iso Packer Builder.
This Example is written in hcl
---
# What's this
This Example builds a vanilla Centos 8 Template. No Provisioning or Post-Processing will be done.
If you want to run this example, you have to replace the following variables with your own values.
```hcl
remote_host = "xenserver.example.org"
remote_username = "root"
remote_password = "very-secret-password"
sr_iso_name = "Local-ISO"
sr_name = "Local-SR"
tools_iso_name = "guest-tools.iso"
```
## Parts of this example
This examples composes the following files from the examples folder
* [centos8-example.pkr.hcl](../../examples/http/centos/centos8-example.pkr.hcl)
* [ks-centos8-example.cfg](../../examples/http/centos/ks-centos8-example.cfg)
## Explanation of centos8-example.pkr.hcl
* `source "xenserver-iso" "example" { } ` directs packer to configure an Artifact named example using the `xenserver-iso` builder
* `iso_url = "http://mirrors.ocf.berkeley.edu/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-dvd1.iso" ` use the iso obtainable from this url
* `iso_checksum_type = "sha1"` the checksum is of type sha1
* `iso_checksum = "aaf9d4b3071c16dbbda01dfe06085e5d0fdac76df323e3bbe87cce4318052247"` The checksum for the ISO.
* `sr_name = "Local-SR"` store the vmdisk used during install on the SR named `Local-SR`
* `sr_iso_name = "Local-ISO"` store the iso used during install on the ISO-SR named `Local-ISO`
* `tools_iso_name = "guest-tools.iso"` mount the guest-tools iso with the name `guest-tools.iso`
* `remote_host = "xenserver.example.org"` the ipadress or fqdn of the xenserver. This should be the pool primary
* `remote_username = "root"` the user with witch to connect.
* `remote_password = "very-secret-password"` the password for the user.
* `vm_name = "packer-centos8-example"` How packer will name the vm.
* `vm_description = "This is an example."` The description field of the vm
* `vm_memory = 4096` the Amount of RAM, in MB
* `disk_size = 4096` the Size of the Primary Disk in MB
* `http_directory = "examples/http/centos8'` Packer will spin up a http-server for serving files to the installing vm. the kickstart file `ks-centos8-examples.cfg` is in this directory
* `boot_wait = "10s'` Wait for 10s after starting the VM before typeing the `boot_command`
* `boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-examples.cfg<enter><wait>"'`
* The command to type into the installing vm.
* `<tab>` a tab Character `\t`
* `text ks=http://` character literals
* `{{ .HTTPIP }}` will be replaced by the local ip-address.
* `:` character literal
* `{{ .HTTPPort }}` will be replaced by the local port. Will be randomly selectet between 8000 and 9000
* `/ks-centos8-examples.cfg` character literals
* `<enter>` an enter character
* `<wait>` wait for 1s
* `ssh_username = "root"` The ssh user packer uses to connect to the VM
* `ssh_password = "centos"` The ssh password packer uses to connect to the VM
* `ssh_wait_timeout = "10m"` consider install failed if unable to connect via ssh 10m into the build
* `shutdown_command = "/sbin/shutdown"` After connection via ssh issue this command to shut down the vm
* `output_directory = "packer-centos8-local"` Store the resulting xva file in this directory
* `keep_vm = "on_success"` Create a template with the vm after a successfull build
* `build { }` Tell packer what to do while builing
* `sources = ["xenserver-iso.example"]` Build the `xenserver.example` without changing any configuration.
## Explanation of ks-centos8-examples.cfg
```
eula --agreed
# agree to the eula of centos
lang en-US.UTF-8
# set the system-locale to en-US.UTF-8
timezone Europe/Berlin
# set the timezone to Europe/Berlin
url --url="http://mirror.centos.org/centos/8.3.2011/BaseOS/x86_64/os/"
# Primary installation mirror
text
skipx
# Install in textmode, do not configure X11
firstboot --disable
# Dont do any configuration on first boot
rootpw --plaintext centos
# set the reboot to "centos"
firewall --enabled --ssh
# enable the firewall, allow ssh
selinux --enforcing
# ensure selinux is in enforcing mode
logging --level=info
# Installation logging level
network --bootproto=dhcp --device=eth0 --onboot=on
# configure the network with dhcp on install
clearpart --all
zerombr
bootloader --location=mbr
# Clear all partitioning on all disk
# Zero the MBR section
# Install the bootloader into the MBR
part / --asprimary --fstype="ext4" --size=1024 --grow
# / shall the a primary partition with ext4
# with a mimimul size of 1024 MB, but growing to the actual size of the disk
%packages
@base
%end
# install all packages of the core group
reboot --eject
# After finishing eject all CD-Disk and reboot
```

View File

@ -0,0 +1,127 @@
---
layout: "docs"
page_title: "XenServer-iso Commented Example"
description: |-
This is a Commented example for how to use the xenserver-iso Packer Builder.
This Example is written in hcl
---
# What's this
This Example builds a vanilla Centos 8 Template. No Provisioning or Post-Processing will be done.
If you want to run this example, you have to replace the following variables with your own values.
```hcl
remote_host = "xenserver.example.org"
remote_username = "root"
remote_password = "very-secret-password"
sr_iso_name = "Local-ISO"
sr_name = "Local-SR"
tools_iso_name = "guest-tools.iso"
```
## Parts of this example
This examples composes the following files from the examples folder
* [centos8-example.pkr.hcl](../../examples/http/centos/centos8-example.pkr.hcl)
* [ks-centos8-example.cfg](../../examples/http/centos/ks-centos8-example.cfg)
## Explanation of centos8-example.pkr.hcl
* `source "xenserver-iso" "example" { } ` directs packer to configure an Artifact named example using the `xenserver-iso` builder
* `iso_url = "http://mirrors.ocf.berkeley.edu/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-dvd1.iso" ` use the iso obtainable from this url
* `iso_checksum_type = "sha1"` the checksum is of type sha1
* `iso_checksum = "aaf9d4b3071c16dbbda01dfe06085e5d0fdac76df323e3bbe87cce4318052247"` The checksum for the ISO.
* `sr_name = "Local-SR"` store the vmdisk used during install on the SR named `Local-SR`
* `sr_iso_name = "Local-ISO"` store the iso used during install on the ISO-SR named `Local-ISO`
* `tools_iso_name = "guest-tools.iso"` mount the guest-tools iso with the name `guest-tools.iso`
* `remote_host = "xenserver.example.org"` the ipadress or fqdn of the xenserver. This should be the pool primary
* `remote_username = "root"` the user with witch to connect.
* `remote_password = "very-secret-password"` the password for the user.
* `vm_name = "packer-centos8-example"` How packer will name the vm.
* `vm_description = "This is an example."` The description field of the vm
* `vm_memory = 4096` the Amount of RAM, in MB
* `disk_size = 4096` the Size of the Primary Disk in MB
* `http_directory = "examples/http/centos8'` Packer will spin up a http-server for serving files to the installing vm. the kickstart file `ks-centos8-examples.cfg` is in this directory
* `boot_wait = "10s'` Wait for 10s after starting the VM before typeing the `boot_command`
* `boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-examples.cfg<enter><wait>"'`
* The command to type into the installing vm.
* `<tab>` a tab Character `\t`
* `text ks=http://` character literals
* `{{ .HTTPIP }}` will be replaced by the local ip-address.
* `:` character literal
* `{{ .HTTPPort }}` will be replaced by the local port. Will be randomly selectet between 8000 and 9000
* `/ks-centos8-examples.cfg` character literals
* `<enter>` an enter character
* `<wait>` wait for 1s
* `ssh_username = "root"` The ssh user packer uses to connect to the VM
* `ssh_password = "centos"` The ssh password packer uses to connect to the VM
* `ssh_wait_timeout = "10m"` consider install failed if unable to connect via ssh 10m into the build
* `shutdown_command = "/sbin/shutdown"` After connection via ssh issue this command to shut down the vm
* `output_directory = "packer-centos8-local"` Store the resulting xva file in this directory
* `keep_vm = "on_success"` Create a template with the vm after a successfull build
* `build { }` Tell packer what to do while builing
* `sources = ["xenserver-iso.example"]` Build the `xenserver.example` without changing any configuration.
## Explanation of ks-centos8-examples.cfg
```
eula --agreed
# agree to the eula of centos
lang en-US.UTF-8
# set the system-locale to en-US.UTF-8
timezone Europe/Berlin
# set the timezone to Europe/Berlin
url --url="http://mirror.centos.org/centos/8.3.2011/BaseOS/x86_64/os/"
# Primary installation mirror
text
skipx
# Install in textmode, do not configure X11
firstboot --disable
# Dont do any configuration on first boot
rootpw --plaintext centos
# set the reboot to "centos"
firewall --enabled --ssh
# enable the firewall, allow ssh
selinux --enforcing
# ensure selinux is in enforcing mode
logging --level=info
# Installation logging level
network --bootproto=dhcp --device=eth0 --onboot=on
# configure the network with dhcp on install
clearpart --all
zerombr
bootloader --location=mbr
# Clear all partitioning on all disk
# Zero the MBR section
# Install the bootloader into the MBR
part / --asprimary --fstype="ext4" --size=1024 --grow
# / shall the a primary partition with ext4
# with a mimimul size of 1024 MB, but growing to the actual size of the disk
%packages
@base
%end
# install all packages of the core group
reboot --eject
# After finishing eject all CD-Disk and reboot
```

View File

@ -1,11 +1,32 @@
## 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 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.
2. Run `packer build path/to/defenition.pkr.hcl`
so for example:
`packer build examples/centos/centos8-netinstall.pkr.hcl`
### Ubuntu
This example has not yet updated to HCL.
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.
@ -18,15 +39,13 @@ packer build -debug --var sr_name='Local storage' --var sr_iso_name=LocalISO ex
packer build -debug --var sr_name='Local storage' --var sr_iso_name=LocalISO examples/ubuntu-2004.json
```
### 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 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.

View File

@ -0,0 +1,53 @@
source "xenserver-iso" "example" {
#
# Where to get the iso
#
iso_url = "http://mirrors.ocf.berkeley.edu/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-dvd1.iso"
iso_checksum_type = "sha1"
iso_checksum = "aaf9d4b3071c16dbbda01dfe06085e5d0fdac76df323e3bbe87cce4318052247"
#
# Where to store the ISO, vm-disk and where to find the xentools iso
#
sr_iso_name = "Local-ISO"
sr_name = "Local-SR"
tools_iso_name = "guest-tools.iso"
#
# How to communicate with the xenserver
#
remote_host = "xenserver.example.org"
remote_username = "root"
remote_password = "very-secret-password"
#
# Basic info for the vm
#
vm_name = "packer-centos8-example"
vm_description = "This is an example."
vm_memory = 4096
disk_size = 4096
#
# For the installation
#
http_directory = "examples/http/centos8"
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-examples.cfg<enter><wait>"]
boot_wait = "10s"
#
# how packer contacts the vm
#
ssh_username = "root"
ssh_password = "centos"
ssh_wait_timeout = "10m"
shutdown_command = "/sbin/shutdown"
#
# What to do with the resulting VM
#
output_directory = "packer-centos8-local"
keep_vm = "on_success"
}
#
# Operations to do while building.
# Any provisioning would be done here
#
build {
sources = ["xenserver-iso.example"]
}

View File

@ -0,0 +1,73 @@
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" "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"
shutdown_command = "/sbin/shutdown"
output_directory = "packer-centos8-local"
keep_vm = "always"
}
build {
sources = ["xenserver-iso.centos8-local"]
}

View File

@ -0,0 +1,73 @@
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" "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"
shutdown_command = "/sbin/shutdown"
output_directory = "packer-centos8-netinstall"
keep_vm = "always"
}
build {
sources = ["xenserver-iso.centos8-netinstall"]
}

View File

@ -0,0 +1,52 @@
eula --agreed
# agree to the eula of centos
lang en-US.UTF-8
# set the system-locale to en-US.UTF-8
timezone Europe/Berlin
# set the timezone to Europe/Berlin
url --url="http://mirror.centos.org/centos/8.3.2011/BaseOS/x86_64/os/"
# Primary installation mirror
text
skipx
# Install in textmode, do not configure X11
firstboot --disable
# Dont do any configuration on first boot
rootpw --plaintext centos
# set the reboot to "centos"
firewall --enabled --ssh
# enable the firewall, allow ssh
selinux --enforcing
# ensure selinux is in enforcing mode
logging --level=info
# Installation logging level
network --bootproto=dhcp --device=eth0 --onboot=on
# configure the network with dhcp on install
clearpart --all
zerombr
bootloader --location=mbr
# Clear all partitioning on all disk
# Zero the MBR section
# Install the bootloader into the MBR
part / --asprimary --fstype="ext4" --size=1024 --grow
# / shall the a primary partition with ext4
# with a mimimul size of 1024 MB, but growing to the actual size of the disk
%packages
@base
%end
# install all packages of the core group
reboot --eject
# After finishing eject all CD-Disk and reboot

View 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

View 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

View File

@ -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