From d4d97c18f739b650097eabc80be69769a1267124 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 2 Feb 2021 13:25:59 +0100 Subject: [PATCH 1/4] added centos8-netinstall --- examples/centos/centos8-netinstall.pkr.hcl | 73 +++++++++++++++++++ .../http/centos8/ks-centos8-netinstall.cfg | 46 ++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 examples/centos/centos8-netinstall.pkr.hcl create mode 100644 examples/http/centos8/ks-centos8-netinstall.cfg diff --git a/examples/centos/centos8-netinstall.pkr.hcl b/examples/centos/centos8-netinstall.pkr.hcl new file mode 100644 index 0000000..cc54b20 --- /dev/null +++ b/examples/centos/centos8-netinstall.pkr.hcl @@ -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 = [" text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-netinstall.cfg"] + 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"] +} \ No newline at end of file diff --git a/examples/http/centos8/ks-centos8-netinstall.cfg b/examples/http/centos8/ks-centos8-netinstall.cfg new file mode 100644 index 0000000..c9e7dc7 --- /dev/null +++ b/examples/http/centos8/ks-centos8-netinstall.cfg @@ -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 + From 06c5188c9f65cad6c0bb2f6b50e7047a6f96c937 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 2 Feb 2021 13:33:48 +0100 Subject: [PATCH 2/4] updated examples/README.md to refekt current state --- examples/README.md | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/README.md b/examples/README.md index 60f7d32..935cdb9 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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. - +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 +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` -# 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 -``` ### 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. From ca10207b4a4ce667120147f94e5f2c25afe0a56d Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 2 Feb 2021 17:34:43 +0100 Subject: [PATCH 3/4] added local DVD install example --- examples/centos/centos8-local.pkr.hcl | 73 ++++++++++++++++++++++ examples/http/centos8/ks-centos8-local.cfg | 47 ++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 examples/centos/centos8-local.pkr.hcl create mode 100644 examples/http/centos8/ks-centos8-local.cfg diff --git a/examples/centos/centos8-local.pkr.hcl b/examples/centos/centos8-local.pkr.hcl new file mode 100644 index 0000000..5e508c8 --- /dev/null +++ b/examples/centos/centos8-local.pkr.hcl @@ -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 = [" text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-local.cfg"] + 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"] +} \ No newline at end of file diff --git a/examples/http/centos8/ks-centos8-local.cfg b/examples/http/centos8/ks-centos8-local.cfg new file mode 100644 index 0000000..a275dea --- /dev/null +++ b/examples/http/centos8/ks-centos8-local.cfg @@ -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 + From 567ecb14b1cc7aafeb0476c2eeb4c2b5b022c695 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 3 Feb 2021 15:05:14 +0100 Subject: [PATCH 4/4] Added a commented example of a centos8 build --- docs/builders/Commented-Example.md | 127 +++++++++++++++++++ examples/centos/centos8-example.pkr.hcl | 53 ++++++++ examples/http/centos8/ks-centos8-example.cfg | 52 ++++++++ 3 files changed, 232 insertions(+) create mode 100644 docs/builders/Commented-Example.md create mode 100644 examples/centos/centos8-example.pkr.hcl create mode 100644 examples/http/centos8/ks-centos8-example.cfg diff --git a/docs/builders/Commented-Example.md b/docs/builders/Commented-Example.md new file mode 100644 index 0000000..077bc8b --- /dev/null +++ b/docs/builders/Commented-Example.md @@ -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 = [" text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-examples.cfg"'` + * The command to type into the installing vm. + * `` 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 + * `` an enter character + * `` 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 +``` diff --git a/examples/centos/centos8-example.pkr.hcl b/examples/centos/centos8-example.pkr.hcl new file mode 100644 index 0000000..830416e --- /dev/null +++ b/examples/centos/centos8-example.pkr.hcl @@ -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 = [" text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-centos8-examples.cfg"] + 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"] +} \ No newline at end of file diff --git a/examples/http/centos8/ks-centos8-example.cfg b/examples/http/centos8/ks-centos8-example.cfg new file mode 100644 index 0000000..a920fec --- /dev/null +++ b/examples/http/centos8/ks-centos8-example.cfg @@ -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 \ No newline at end of file