Skip to content

Commit

Permalink
feat: add additional packages (#800)
Browse files Browse the repository at this point in the history
Adds additional configuration to install packages for Linux Distributions.

Signed-off-by: Stéphane Este-Gracias <[email protected]>
  • Loading branch information
sestegra authored Dec 18, 2023
1 parent 4c9d59e commit 7fee81c
Show file tree
Hide file tree
Showing 92 changed files with 316 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:rocket: **Enhancement**:

- Adds templates with unit tests for managing custom network and storage configurations for Linux Distributions. [GH-473](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/473)
- Adds additional configuration to install packages for Linux Distributions. [GH-800](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/800)

## v23.11

Expand Down
3 changes: 3 additions & 0 deletions builds/linux/almalinux/8/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ dnf makecache
dnf install epel-release -y
dnf makecache
dnf install -y sudo open-vm-tools perl
%{ if additional_packages != "" ~}
dnf install -y ${additional_packages}
%{ endif ~}
echo "${build_username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/${build_username}
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
%end
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/almalinux/8/linux-almalinux.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ locals {
vm_guest_os_language = var.vm_guest_os_language
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
device = var.vm_network_device
ip = var.vm_ip_address
netmask = var.vm_ip_netmask
gateway = var.vm_ip_gateway
dns = var.vm_dns_list
})
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
device = var.vm_disk_device
swap = var.vm_disk_use_swap
partitions = var.vm_disk_partitions
lvm = var.vm_disk_lvm
})
additional_packages = join(" ", var.additional_packages)
})
}
data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg"
Expand Down
2 changes: 1 addition & 1 deletion builds/linux/almalinux/8/variables-storage.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ variable "vm_disk_partitions" {

variable "vm_disk_lvm" {
type = list(object({
name = string
name = string
partitions = list(object({
name = string
size = number
Expand Down
8 changes: 8 additions & 0 deletions builds/linux/almalinux/8/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,11 @@ variable "common_hcp_packer_registry_enabled" {
description = "Enable the HCP Packer registry."
default = false
}

// Additional Settings

variable "additional_packages" {
type = list(string)
description = "Additional packages to install."
default = []
}
3 changes: 3 additions & 0 deletions builds/linux/almalinux/9/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ dnf makecache
dnf install epel-release -y
dnf makecache
dnf install -y sudo open-vm-tools perl
%{ if additional_packages != "" ~}
dnf install -y ${additional_packages}
%{ endif ~}
echo "${build_username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/${build_username}
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
%end
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/almalinux/9/linux-almalinux.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ locals {
vm_guest_os_language = var.vm_guest_os_language
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
device = var.vm_network_device
ip = var.vm_ip_address
netmask = var.vm_ip_netmask
gateway = var.vm_ip_gateway
dns = var.vm_dns_list
})
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
device = var.vm_disk_device
swap = var.vm_disk_use_swap
partitions = var.vm_disk_partitions
lvm = var.vm_disk_lvm
})
additional_packages = join(" ", var.additional_packages)
})
}
data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg"
Expand Down
2 changes: 1 addition & 1 deletion builds/linux/almalinux/9/variables-storage.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ variable "vm_disk_partitions" {

variable "vm_disk_lvm" {
type = list(object({
name = string
name = string
partitions = list(object({
name = string
size = number
Expand Down
8 changes: 8 additions & 0 deletions builds/linux/almalinux/9/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,11 @@ variable "common_hcp_packer_registry_enabled" {
description = "Enable the HCP Packer registry."
default = false
}

// Additional Settings

variable "additional_packages" {
type = list(string)
description = "Additional packages to install."
default = []
}
3 changes: 3 additions & 0 deletions builds/linux/centos/7/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ yum makecache
yum install epel-release -y
yum makecache
yum install -y sudo open-vm-tools perl
%{ if additional_packages != "" ~}
yum install -y ${additional_packages}
%{ endif ~}
echo "${build_username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/${build_username}
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
%end
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/centos/7/linux-centos.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ locals {
vm_guest_os_language = var.vm_guest_os_language
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
device = var.vm_network_device
ip = var.vm_ip_address
netmask = var.vm_ip_netmask
gateway = var.vm_ip_gateway
dns = var.vm_dns_list
})
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
device = var.vm_disk_device
swap = var.vm_disk_use_swap
partitions = var.vm_disk_partitions
lvm = var.vm_disk_lvm
})
additional_packages = join(" ", var.additional_packages)
})
}
data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg"
Expand Down
2 changes: 1 addition & 1 deletion builds/linux/centos/7/variables-storage.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ variable "vm_disk_partitions" {

variable "vm_disk_lvm" {
type = list(object({
name = string
name = string
partitions = list(object({
name = string
size = number
Expand Down
8 changes: 8 additions & 0 deletions builds/linux/centos/7/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,11 @@ variable "common_hcp_packer_registry_enabled" {
description = "Enable the HCP Packer registry."
default = false
}

// Additional Settings

variable "additional_packages" {
type = list(string)
description = "Additional packages to install."
default = []
}
3 changes: 3 additions & 0 deletions builds/linux/centos/8-stream/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ dnf makecache
dnf install epel-release -y
dnf makecache
dnf install -y sudo open-vm-tools perl
%{ if additional_packages != "" ~}
dnf install -y ${additional_packages}
%{ endif ~}
echo "${build_username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/${build_username}
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
%end
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/centos/8-stream/linux-centos-stream.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ locals {
vm_guest_os_language = var.vm_guest_os_language
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
device = var.vm_network_device
ip = var.vm_ip_address
netmask = var.vm_ip_netmask
gateway = var.vm_ip_gateway
dns = var.vm_dns_list
})
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
device = var.vm_disk_device
swap = var.vm_disk_use_swap
partitions = var.vm_disk_partitions
lvm = var.vm_disk_lvm
})
additional_packages = join(" ", var.additional_packages)
})
}
data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg"
Expand Down
2 changes: 1 addition & 1 deletion builds/linux/centos/8-stream/variables-storage.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ variable "vm_disk_partitions" {

variable "vm_disk_lvm" {
type = list(object({
name = string
name = string
partitions = list(object({
name = string
size = number
Expand Down
8 changes: 8 additions & 0 deletions builds/linux/centos/8-stream/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,11 @@ variable "common_hcp_packer_registry_enabled" {
description = "Enable the HCP Packer registry."
default = false
}

// Additional Settings

variable "additional_packages" {
type = list(string)
description = "Additional packages to install."
default = []
}
3 changes: 3 additions & 0 deletions builds/linux/centos/9-stream/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ dnf makecache
dnf install epel-release -y
dnf makecache
dnf install -y sudo open-vm-tools perl
%{ if additional_packages != "" ~}
dnf install -y ${additional_packages}
%{ endif ~}
echo "${build_username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/${build_username}
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
%end
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/centos/9-stream/linux-centos-stream.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ locals {
vm_guest_os_language = var.vm_guest_os_language
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
device = var.vm_network_device
ip = var.vm_ip_address
netmask = var.vm_ip_netmask
gateway = var.vm_ip_gateway
dns = var.vm_dns_list
})
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
device = var.vm_disk_device
swap = var.vm_disk_use_swap
partitions = var.vm_disk_partitions
lvm = var.vm_disk_lvm
})
additional_packages = join(" ", var.additional_packages)
})
}
data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg"
Expand Down
2 changes: 1 addition & 1 deletion builds/linux/centos/9-stream/variables-storage.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ variable "vm_disk_partitions" {

variable "vm_disk_lvm" {
type = list(object({
name = string
name = string
partitions = list(object({
name = string
size = number
Expand Down
8 changes: 8 additions & 0 deletions builds/linux/centos/9-stream/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,11 @@ variable "common_hcp_packer_registry_enabled" {
description = "Enable the HCP Packer registry."
default = false
}

// Additional Settings

variable "additional_packages" {
type = list(string)
description = "Additional packages to install."
default = []
}
2 changes: 1 addition & 1 deletion builds/linux/debian/11/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ d-i passwd/user-password-crypted password ${build_password_encrypted}

# Package Configuration
d-i pkgsel/run_tasksel boolean false
d-i pkgsel/include string openssh-server open-vm-tools python3-apt perl
d-i pkgsel/include string openssh-server open-vm-tools python3-apt perl ${additional_packages}

# Add User to Sudoers
d-i preseed/late_command string \
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/debian/11/linux-debian.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ locals {
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
common_data_source = var.common_data_source
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
device = var.vm_network_device
ip = var.vm_ip_address
netmask = var.vm_ip_netmask
gateway = var.vm_ip_gateway
dns = var.vm_dns_list
})
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
device = var.vm_disk_device
swap = var.vm_disk_use_swap
partitions = var.vm_disk_partitions
lvm = var.vm_disk_lvm
})
additional_packages = join(" ", var.additional_packages)
})
}
data_source_command = var.common_data_source == "http" ? "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "file=/media/ks.cfg"
Expand Down
2 changes: 1 addition & 1 deletion builds/linux/debian/11/variables-storage.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ variable "vm_disk_partitions" {

variable "vm_disk_lvm" {
type = list(object({
name = string
name = string
partitions = list(object({
name = string
size = number
Expand Down
8 changes: 8 additions & 0 deletions builds/linux/debian/11/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,11 @@ variable "common_hcp_packer_registry_enabled" {
description = "Enable the HCP Packer registry."
default = false
}

// Additional Settings

variable "additional_packages" {
type = list(string)
description = "Additional packages to install."
default = []
}
2 changes: 1 addition & 1 deletion builds/linux/debian/12/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ d-i passwd/user-password-crypted password ${build_password_encrypted}

# Package Configuration
d-i pkgsel/run_tasksel boolean false
d-i pkgsel/include string openssh-server open-vm-tools python3-apt perl
d-i pkgsel/include string openssh-server open-vm-tools python3-apt perl ${additional_packages}

# Add User to Sudoers
d-i preseed/late_command string \
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/debian/12/linux-debian.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ locals {
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
common_data_source = var.common_data_source
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", {
device = var.vm_network_device
ip = var.vm_ip_address
netmask = var.vm_ip_netmask
gateway = var.vm_ip_gateway
dns = var.vm_dns_list
})
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", {
device = var.vm_disk_device
swap = var.vm_disk_use_swap
partitions = var.vm_disk_partitions
lvm = var.vm_disk_lvm
})
additional_packages = join(" ", var.additional_packages)
})
}
data_source_command = var.common_data_source == "http" ? "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "file=/media/ks.cfg"
Expand Down
2 changes: 1 addition & 1 deletion builds/linux/debian/12/variables-storage.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ variable "vm_disk_partitions" {

variable "vm_disk_lvm" {
type = list(object({
name = string
name = string
partitions = list(object({
name = string
size = number
Expand Down
8 changes: 8 additions & 0 deletions builds/linux/debian/12/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,11 @@ variable "common_hcp_packer_registry_enabled" {
description = "Enable the HCP Packer registry."
default = false
}

// Additional Settings

variable "additional_packages" {
type = list(string)
description = "Additional packages to install."
default = []
}
3 changes: 3 additions & 0 deletions builds/linux/oracle/8/data/ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ skipx
dnf install -y oracle-epel-release-el8
dnf makecache
dnf install -y sudo open-vm-tools perl
%{ if additional_packages != "" ~}
dnf install -y ${additional_packages}
%{ endif ~}
echo "${build_username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/${build_username}
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
%end
Expand Down
Loading

0 comments on commit 7fee81c

Please sign in to comment.