diff --git a/CHANGELOG.md b/CHANGELOG.md index bfbc31c5d..e80fb8af1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Adds a development container for Visual Studio Code. [GH-700](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/700) - Adds an example `.gitlab.yml` file for GitLab CI/CD. [GH-675](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/675) - Adds a `build-ci.tmpl` that can be used to create or update the `.gitlab-ci.yml` file using gomplate. [GH-675](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/675) +- Adds a `--debug` option to `./build.sh` to enable debug logging for Packer. :bug: **Bugfix**: diff --git a/build.sh b/build.sh index e41948067..1a041ca4d 100755 --- a/build.sh +++ b/build.sh @@ -17,7 +17,20 @@ follow_link() { } SCRIPT_PATH=$(realpath "$(dirname "$(follow_link "$0")")") -CONFIG_PATH=$(realpath "${1:-${SCRIPT_PATH}/config}") +debug=false + +if [ "$1" == "--debug" ] +then + debug=true + shift +fi + +if [ -n "$1" ] +then + CONFIG_PATH=$(realpath "$1") +else + CONFIG_PATH=$(realpath "${SCRIPT_PATH}/config") +fi menu_option_1() { INPUT_PATH="$SCRIPT_PATH"/builds/linux/photon/5/ @@ -38,7 +51,12 @@ menu_option_1() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -69,7 +87,12 @@ menu_option_2() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -100,7 +123,12 @@ menu_option_3() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -131,7 +159,12 @@ menu_option_4() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -162,7 +195,12 @@ menu_option_5() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -193,7 +231,12 @@ menu_option_6() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -224,7 +267,12 @@ menu_option_7() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -256,7 +304,12 @@ menu_option_8() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -288,7 +341,12 @@ menu_option_9() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -320,7 +378,12 @@ menu_option_10() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -351,7 +414,12 @@ menu_option_11() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -382,7 +450,12 @@ menu_option_12() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -413,7 +486,12 @@ menu_option_13() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -444,7 +522,12 @@ menu_option_14() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -475,7 +558,12 @@ menu_option_15() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -506,7 +594,12 @@ menu_option_16() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -537,7 +630,12 @@ menu_option_17() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -569,7 +667,12 @@ menu_option_18() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -600,7 +703,12 @@ menu_option_19() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -632,7 +740,12 @@ menu_option_20() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ @@ -661,7 +774,12 @@ menu_option_21() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi --only vsphere-iso.windows-server-standard-dexp,vsphere-iso.windows-server-standard-core \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ @@ -691,7 +809,12 @@ menu_option_22() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi --only vsphere-iso.windows-server-datacenter-dexp,vsphere-iso.windows-server-datacenter-core \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ @@ -721,7 +844,12 @@ menu_option_23() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ @@ -750,7 +878,12 @@ menu_option_24() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi --only vsphere-iso.windows-server-standard-dexp,vsphere-iso.windows-server-standard-core \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ @@ -780,7 +913,12 @@ menu_option_25() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi --only vsphere-iso.windows-server-datacenter-dexp,vsphere-iso.windows-server-datacenter-core \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ @@ -810,7 +948,12 @@ menu_option_26() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ @@ -839,7 +982,12 @@ menu_option_27() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi --only vsphere-iso.windows-desktop-ent \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ @@ -869,7 +1017,12 @@ menu_option_28() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi --only vsphere-iso.windows-desktop-pro \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ @@ -899,7 +1052,12 @@ menu_option_29() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ @@ -928,7 +1086,12 @@ menu_option_30() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi --only vsphere-iso.windows-desktop-ent \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ @@ -958,7 +1121,12 @@ menu_option_31() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi --only vsphere-iso.windows-desktop-pro \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ @@ -997,8 +1165,12 @@ until [ "$selection" = "0" ]; do echo " / ____/ /_/ / /__/ ,< / __/ / / /_/ / /_/ / / / /_/ (__ ) " echo "/_/ \__,_/\___/_/|_|\___/_/ /_____/\__,_/_/_/\__,_/____/ " echo "" - echo -n " Select a HashiCorp Packer build for VMware vSphere:" - echo "" + if [ "$debug" = true ] + then + echo -e "\e[31m Select a HashiCorp Packer build for VMware vSphere (debug mode): \e[0m" + else + echo " Select a HashiCorp Packer build for VMware vSphere:" + fi echo "" echo " Linux Distribution:" echo "" diff --git a/build.tmpl b/build.tmpl index 46f30c3ac..b45c19881 100644 --- a/build.tmpl +++ b/build.tmpl @@ -17,7 +17,20 @@ follow_link() { } SCRIPT_PATH=$(realpath "$(dirname "$(follow_link "$0")")") -CONFIG_PATH=$(realpath "${1:-${SCRIPT_PATH}/config}") +debug=false + +if [ "$1" == "--debug" ] +then + debug=true + shift +fi + +if [ -n "$1" ] +then + CONFIG_PATH=$(realpath "$1") +else + CONFIG_PATH=$(realpath "${SCRIPT_PATH}/config") +fi {{- $func_index := 0 }} {{ range $menu := (ds "build").menu -}} @@ -48,7 +61,12 @@ menu_option_{{ $func_index }}() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + if [ "$debug" = true ] + then + packer build -force -on-error=ask -debug "$INPUT_PATH" + else + packer build -force -on-error=ask "$INPUT_PATH" + fi {{- if (coll.Has $submenu.build "only") }} --only {{ join $submenu.build.only "," }} \ {{- end -}} @@ -98,8 +116,12 @@ until [ "$selection" = "0" ]; do echo " / ____/ /_/ / /__/ ,< / __/ / / /_/ / /_/ / / / /_/ (__ ) " echo "/_/ \__,_/\___/_/|_|\___/_/ /_____/\__,_/_/_/\__,_/____/ " echo "" - echo -n " Select a HashiCorp Packer build for VMware vSphere:" - echo "" + if [ "$debug" = true ] + then + echo -e "\e[31m Select a HashiCorp Packer build for VMware vSphere (debug mode): \e[0m" + else + echo " Select a HashiCorp Packer build for VMware vSphere:" + fi echo "" {{- $menu_index := 0 }} {{- range $menu := (ds "build").menu }}