Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added 9.4 versions and updated build.sh #927

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@

- Updates Red Hat Enterprise Linux 9 to 9.4 release.
[#925](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/925)
- Updates Oracle Linux 9 to 9.4 release.
[#927](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/927)
- Updates Almalinux 9 to 9.4 release.
[#927](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/927)
- Updates Rocky Linux 9 to 9.4 release.
[#927](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/927)
- Removes CentOS Stream 8 from the project.

On 31 May 2024, CentOS Stream 8 reached the end of life.
Expand Down
12 changes: 12 additions & 0 deletions ansible/roles/base/tasks/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
state: latest
when: ansible_distribution == 'AlmaLinux' and ansible_distribution_version | int >= 8 and enable_cloudinit == 'true'

- name: "Installing cloud-init."
command:
cmd: dnf install -y cloud-init
become: yes
when: enable_cloudinit == 'true' and ansible_distribution == 'Rocky'

- name: "Installing cloud-init."
command:
cmd: dnf install -y cloud-init
become: yes
when: enable_cloudinit == 'true' and ansible_distribution == 'OracleLinux'

- block:
- name: "Updating the operating system."
dnf:
Expand Down
231 changes: 157 additions & 74 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,120 @@ script_path=$(
cd "$(dirname "$(follow_link "$0")")"
pwd
)

run_check_dependencies=false
run_check_jq=false
run_check_packer=false
run_check_anisble=false
run_show_help=false

# This function prompts the user to press Enter to continue.
press_enter_continue() {
printf "Press \033[32mEnter\033[0m to continue.\n"
read -r
exec "$0"
}

# This function prompts the user to press Enter to exit.
press_enter_exit() {
printf "Press \033[31mEnter\033[0m to exit.\n"
read -r
exit 0
}

# Set config_path if it's not already set
if [ -z "$config_path" ]; then
config_path=$(
cd "${script_path}/config"
pwd
)
fi
# Set the default values for the variables.

# This function displays the information about the script and project.
info() {
project_name=$(get_project_info "name")
project_description=$(get_project_info "description")
project_version=$(get_project_info "version")
project_license=$(get_project_info "license[0].name")
project_github_url=$(get_project_info "urls.github")
project_docs_url=$(get_project_info "urls.documentation")
clear
printf "\033[32m$project_name\033[0m: \033[34m$project_version\033[0m\n\n"
printf "Copyright 2023-$(date +%Y) Broadcom. All Rights Reserved.\n\n"
printf "License: $project_license\n\n"
printf "$project_description\n\n"
printf "GitHub Repository: $project_github_url\n"
printf "Documentation: $project_docs_url\n\n"
show_help "continue"
press_enter
}

# This function displays the help message.
show_help() {
local exit_after=${1:-"exit"}
script_name=$(basename $0)
printf "Usage: $script_name [options]\n\n"
printf "Options:\n"
printf " --deps, -d, -D Check the dependencies.\n"
printf " --json, -j, -J Specify the JSON file path.\n"
printf " --show, -s, -S Display the build command used to build the image.\n"
printf " --help, -h, -H Display this help message.\n\n"
if [[ -z "$input" ]]; then
[ "$exit_after" = "exit" ] && exit 0
else
printf "Press \033[32mEnter\033[0m to continue."
fi
}

json_path="project.json"
os_names=$(jq -r '.os[] | .name' $json_path)
os_array=($os_names)
# Check for jq
check_jq() {
if ! command -v jq &>/dev/null; then
echo -e "\033[0;31m[✘]\033[0m jq is not installed."
exit 1
fi
}

check_ansible() {
cmd="ansible"
local deps_version=$(jq -r --arg cmd $cmd '.dependencies[] | select(.name == $cmd ) | .version_requirement' $json_path)
required_version=$(echo $deps_version | tr -d '>=' | xargs)
if ! command -v ansible &>/dev/null; then
echo -e "\033[0;31m[✘]\033[0mAnsible is not installed. $required_version or later is required."
exit 1
else
installed_ansible_version=$(ansible --version | head -n 1 | awk '{print $3}' | tr -d '[]')
if [ "$(printf '%s\n' "$required_version" "$installed_ansible_version" | sort -V | head -n1)" != "$required_version" ]; then
echo -e "\033[0;31m[✘]\033[0mansible-core $installed_ansible_version installed. $required_version or later is required."
exit 1
fi
fi
}

check_packer() {
cmd="packer"
local deps_version=$(jq -r --arg cmd $cmd '.dependencies[] | select(.name == $cmd ) | .version_requirement' $json_path)
required_version=$(echo $deps_version | tr -d '>=' | xargs)
if ! command -v $cmd &>/dev/null; then
echo -e "\033[0;31m[✘]\033[0mPacker is not installed. $required_version or later is required."
exit 1
else
installed_packer_version=$(packer version | head -n 1 | awk '{print $2}' | tr -d 'v')
if [ "$(printf '%s\n' "$required_version" "$installed_packer_version" | sort -V | head -n1)" != "$required_version" ]; then
echo -e "\033[0;31m[✘]\033[0mPacker $installed_packer_version installed. $required_version or later is required."
exit 1
fi
fi
}

# Check if check_jq needs to be run
check_jq

# Check if check_ansible needs to be run
check_ansible

# Check if check_packer needs to be run
check_packer

check_command() {
cmd=$1
Expand All @@ -49,22 +152,22 @@ check_command() {
if echo -e "$required_version\n$installed_version" | sort -V -C; then
echo -e "$CHECKMARK $capitalized_cmd: $installed_version is installed. $required_version or later is required."
else
echo -e "$CROSSMARK $capitalized_cmd: $installed_version is installed. $required_version or later is required"
echo -e "$CROSSMARK $capitalized_cmd: $installed_version is installed. $required_version or later is required."
fi
;;
"==")
if [ "$installed_version" == "$required_version" ]; then
echo -e "$CHECKMARK $capitalized_cmd: $installed_version is installed. $required_version or later is required"
echo -e "$CHECKMARK $capitalized_cmd: $installed_version is installed. $required_version or later is required."
else
echo -e "$CROSSMARK $capitalized_cmd: $installed_version is installed. $required_version or later is required"
echo -e "$CROSSMARK $capitalized_cmd: $installed_version is installed. $required_version or later is required."
fi
;;
*)
echo -e "$CROSSMARK Unknown operator: $operator"
;;
esac
else
echo -e "$CROSSMARK $capitalized_cmd is not installed. $required_version or later required"
echo -e "$CROSSMARK $capitalized_cmd is not installed. $required_version or later required."
fi
}

Expand All @@ -84,6 +187,53 @@ check_dependencies() {
fi
}

show_command=0
# Script options.
while (("$#")); do
case "$1" in
--json | -j | -J)
json_path="$2"
run_check_jq=true
shift 2
;;
--deps | -d | -D)
check_dependencies
shift
;;
--show | -s | -S)
show_command=1
shift
;;
--debug | -d | -D)
debug=1
debug_option="-debug"
shift
;;
--help | -h | -H)
run_show_help=true
show_help
shift
;;
*)
config_path=$(realpath "$1")
shift
;;
esac
done

# After the loop, check if show_help needs to be run
if $run_show_help; then
show_help
fi

if $run_check_dependencies; then
check_dependencies
fi

# Set the default values for the variables.
os_names=$(jq -r '.os[] | .name' $json_path)
os_array=($os_names)

# Get the project information from the JSON file.
get_project_info() {
local field=$1
Expand Down Expand Up @@ -145,42 +295,6 @@ press_enter() {
exec $0
}

# This function displays the information about the script and project.
info() {
project_name=$(get_project_info "name")
project_description=$(get_project_info "description")
project_version=$(get_project_info "version")
project_license=$(get_project_info "license[0].name")
project_github_url=$(get_project_info "urls.github")
project_docs_url=$(get_project_info "urls.documentation")
clear
printf "\033[32m$project_name\033[0m: \033[34m$project_version\033[0m\n\n"
printf "Copyright 2023-$(date +%Y) Broadcom. All Rights Reserved.\n\n"
printf "License: $project_license\n\n"
printf "$project_description\n\n"
printf "GitHub Repository: $project_github_url\n"
printf "Documentation: $project_docs_url\n\n"
show_help "continue"
press_enter
}

# This function displays the help message.
show_help() {
local exit_after=${1:-"exit"}
script_name=$(basename $0)
printf "Usage: $script_name [options]\n\n"
printf "Options:\n"
printf " --deps, -d, -D Check the dependencies.\n"
printf " --json, -j, -J Specify the JSON file path.\n"
printf " --show, -s, -S Display the build command used to build the image.\n"
printf " --help, -h, -H Display this help message.\n\n"
if [[ -z "$input" ]]; then
[ "$exit_after" = "exit" ] && exit 0
else
printf "Press \033[32mEnter\033[0m to continue."
fi
}

# This function prompts the user to go back or quit.
prompt_user() {
printf "Enter \033[32mb\033[0m to go back, or \033[31mq\033[0m to quit.\n\n"
Expand Down Expand Up @@ -713,37 +827,6 @@ select_build() {
;;
esac
}
show_command=0
# Script options.
while (("$#")); do
case "$1" in
--json | -j | -J)
json_path="$2"
shift 2
;;
--deps | -d | -D)
check_dependencies
shift
;;
--show | -s | -S)
show_command=1
shift
;;
--debug | -d | -D)
debug=1
debug_option="-debug"
shift
;;
--help | -h | -H)
show_help
shift
;;
*)
config_path=$(realpath "$1")
shift
;;
esac
done

# Check if logging is enabled.
if [[ "$logging_enabled" == "true" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vm_guest_os_keyboard = "us"
vm_guest_os_timezone = "UTC"
vm_guest_os_family = "linux"
vm_guest_os_name = "almalinux"
vm_guest_os_version = "9.3"
vm_guest_os_version = "9.4"

// Virtual Machine Guest Operating System Setting
vm_guest_os_type = "other5xLinux64Guest"
Expand All @@ -34,8 +34,8 @@ vm_network_card = "vmxnet3"

// Removable Media Settings
iso_datastore_path = "iso/linux/almalinux"
iso_content_library_item = "AlmaLinux-9.3-x86_64-dvd"
iso_file = "AlmaLinux-9.3-x86_64-dvd.iso"
iso_content_library_item = "AlmaLinux-9.4-x86_64-dvd"
iso_file = "AlmaLinux-9.4-x86_64-dvd.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
6 changes: 3 additions & 3 deletions builds/linux/oracle/9/linux-oracle.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ vm_guest_os_keyboard = "us"
vm_guest_os_timezone = "UTC"
vm_guest_os_family = "linux"
vm_guest_os_name = "oracle"
vm_guest_os_version = "9.3"
vm_guest_os_version = "9.4"

// Virtual Machine Guest Operating System Setting
vm_guest_os_type = "other5xLinux64Guest"
Expand All @@ -35,8 +35,8 @@ vm_network_card = "vmxnet3"

// Removable Media Settings
iso_datastore_path = "iso/linux/oracle"
iso_content_library_item = "OracleLinux-R9-U3-x86_64-dvd"
iso_file = "OracleLinux-R9-U3-x86_64-dvd.iso"
iso_content_library_item = "OracleLinux-R9-U4-x86_64-dvd"
iso_file = "OracleLinux-R9-U4-x86_64-dvd.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
6 changes: 3 additions & 3 deletions builds/linux/rocky/9/linux-rocky.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ vm_guest_os_keyboard = "us"
vm_guest_os_timezone = "UTC"
vm_guest_os_family = "linux"
vm_guest_os_name = "rocky"
vm_guest_os_version = "9.3"
vm_guest_os_version = "9.4"

// Virtual Machine Guest Operating System Setting
vm_guest_os_type = "other5xLinux64Guest"
Expand All @@ -35,8 +35,8 @@ vm_network_card = "vmxnet3"

// Removable Media Settings
iso_datastore_path = "iso/linux/rocky"
iso_content_library_item = "Rocky-9.3-x86_64-dvd"
iso_file = "Rocky-9.3-x86_64-dvd.iso"
iso_content_library_item = "Rocky-9.4-x86_64-dvd"
iso_file = "Rocky-9.4-x86_64-dvd.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
Loading