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

Support ssh_proxy_* variables for Linux images #40

Merged
merged 6 commits into from
Sep 25, 2021
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
70 changes: 46 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The directory structure of the repository.
│ ├── ansible.pkvars.hcl
│ ├── build.pkvars.hcl
│ ├── common.pkvars.hcl
│ ├── proxy.pkvars.hcl
│ ├── rhsm.pkvars.hcl
│ ├── vsphere.pkvars.hcl
│ ├── linux
Expand Down Expand Up @@ -254,27 +255,21 @@ common_content_library_ovf = true
common_content_library_destroy = true
```

#### **vSphere Variables**
#### **Proxy Variables**

Edit the `/buils/vsphere.pkvars.hcl` file to configure the following:
Edit the `/builds/proxy.pkvars.hcl` file to configure the following:

* vSphere Endpoint and Credentials
* vSphere Settings
* SOCKS proxy settings used for connecting to Linux machine images.
* Credentials for the proxy server (Optional).

Example: `/builds/vsphere.pkvars.hcl`
Example: `/builds/proxy.pkvars.hcl`

```
vsphere_endpoint = "sfo-w01-vc01.sfo.rainpole.io"
vsphere_username = "[email protected]"
vsphere_password = "<plaintext_password>"
vsphere_insecure_connection = true
vsphere_datacenter = "sfo-w01-dc01"
vsphere_cluster = "sfo-w01-cl01"
vsphere_datastore = "sfo-w01-cl01-ds-vsan01"
vsphere_network = "sfo-w01-seg-dhcp"
vsphere_folder = "sfo-w01-fd-templates"
communicator_proxy_host = "proxy.rainpole.io"
communicator_proxy_port = 1080
communicator_proxy_username = "rainpole"
communicator_proxy_password = "<plaintext_password>"
```

#### **Red Hat Subscription Manager Variables**

Edit the `/builds/redhat.pkvars.hcl` file to configure the following:
Expand All @@ -290,6 +285,29 @@ rhsm_password = "<plaintext_password>"

These variables are **only** used if you are performing a Red Hat Enterprise Linux Server build to register the image with Red Hat Subscription Manager and run a `sudo yum update -y` within the shell provisioner. Before the build completes, the machine image is unregistered from Red Hat Subscription Manager.



#### **vSphere Variables**

Edit the `/buils/vsphere.pkvars.hcl` file to configure the following:

* vSphere Endpoint and Credentials
* vSphere Settings

Example: `/builds/vsphere.pkvars.hcl`

```
vsphere_endpoint = "sfo-w01-vc01.sfo.rainpole.io"
vsphere_username = "[email protected]"
vsphere_password = "<plaintext_password>"
vsphere_insecure_connection = true
vsphere_datacenter = "sfo-w01-dc01"
vsphere_cluster = "sfo-w01-cl01"
vsphere_datastore = "sfo-w01-cl01-ds-vsan01"
vsphere_network = "sfo-w01-seg-dhcp"
vsphere_folder = "sfo-w01-fd-templates"
```

#### **Machine Image Variables**

Edit the `*.auto.pkvars.hcl` file in each `builds/<type>/<build>` folder to configure the following virtual machine hardware settings, as required:
Expand All @@ -308,6 +326,18 @@ Edit the `*.auto.pkvars.hcl` file in each `builds/<type>/<build>` folder to conf
Some of the variables may include sensitive information and environmental data that you would prefer not to save to clear text files. You can add there to environmental variables using the example below:

```
export PKR_VAR_ansible_username="<ansible_password>"
export PKR_VAR_ansible_key="<ansible_key>"
export PKR_VAR_build_username="<build_password>"
export PKR_VAR_build_password="<build_password>"
export PKR_VAR_build_password="<build_password_encrypted>"
export PKR_VAR_build_key="<build_key>"
export PKR_VAR_communicator_proxy_host = "<communicator_proxy_host>"
export PKR_VAR_communicator_proxy_port = "<communicator_proxy_port>"
export PKR_VAR_communicator_proxy_username = "<communicator_proxy_username>"
export PKR_VAR_communicator_proxy_password = "communicator_proxy_password>"
export PKR_VAR_rhsm_username="<rhsm_password>"
export PKR_VAR_rhsm_password="<rhsm_password>"
export PKR_VAR_vsphere_endpoint="<vsphere_endpoint_fqdn>"
export PKR_VAR_vsphere_username="<vsphere_username>"
export PKR_VAR_vsphere_password="<vsphere_password>"
Expand All @@ -316,14 +346,6 @@ export PKR_VAR_vsphere_cluster="<vsphere_cluster>"
export PKR_VAR_vsphere_datastore="<vsphere_datastore>>"
export PKR_VAR_vsphere_network="<vsphere_network>"
export PKR_VAR_vsphere_folder="<vsphere_folder>"
export PKR_VAR_build_username="<build_password>"
export PKR_VAR_build_password="<build_password>"
export PKR_VAR_build_password="<build_password_encrypted>"
export PKR_VAR_build_key="<build_key>"
export PKR_VAR_ansible_username="<ansible_password>"
export PKR_VAR_ansible_key="<ansible_key>"
export PKR_VAR_rhsm_username="<rhsm_password>"
export PKR_VAR_rhsm_password="<rhsm_password>"

```
## Step 4 - Modify the Configurations and Scripts
Expand Down Expand Up @@ -485,4 +507,4 @@ Happy building!!!
[vsphere-content-library]: https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-254B2CE8-20A8-43F0-90E8-3F6776C2C896.html
[vsphere-guestosid]: https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html
[vsphere-efi]: https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.security.doc/GUID-898217D4-689D-4EB5-866C-888353FE241C.html
[vsphere-upload]: https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.storage.doc/GUID-58D77EA5-50D9-4A8E-A15A-D7B3ABA11B87.html?hWord=N4IghgNiBcIK4AcIHswBMAEAzAlhApgM4gC+QA
[vsphere-upload]: https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.storage.doc/GUID-58D77EA5-50D9-4A8E-A15A-D7B3ABA11B87.html?hWord=N4IghgNiBcIK4AcIHswBMAEAzAlhApgM4gC+QA
28 changes: 18 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ menu_option_1() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../ansible.pkrvars.hcl" \
-var-file="../../proxy.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
Expand Down Expand Up @@ -56,8 +57,9 @@ menu_option_2() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../ansible.pkrvars.hcl" \
-var-file="../../proxy.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
echo "Done."
}
Expand Down Expand Up @@ -86,8 +88,9 @@ menu_option_3() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../ansible.pkrvars.hcl" \
-var-file="../../proxy.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
echo "Done."
}
Expand Down Expand Up @@ -116,6 +119,7 @@ menu_option_4() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../ansible.pkrvars.hcl" \
-var-file="../../proxy.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" \
-var-file="../../rhsm.pkrvars.hcl" .

Expand Down Expand Up @@ -147,6 +151,7 @@ menu_option_5() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../ansible.pkrvars.hcl" \
-var-file="../../proxy.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
Expand Down Expand Up @@ -177,6 +182,7 @@ menu_option_6() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../ansible.pkrvars.hcl" \
-var-file="../../proxy.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
Expand All @@ -203,6 +209,7 @@ menu_option_7() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../ansible.pkrvars.hcl" \
-var-file="../../proxy.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
Expand Down Expand Up @@ -233,6 +240,7 @@ menu_option_8() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../ansible.pkrvars.hcl" \
-var-file="../../proxy.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
Expand Down Expand Up @@ -293,7 +301,7 @@ menu_option_10() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
echo "Done."
}
Expand Down Expand Up @@ -323,7 +331,7 @@ menu_option_11() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
echo "Done."
}
Expand Down Expand Up @@ -382,7 +390,7 @@ menu_option_13() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
echo "Done."
}
Expand Down Expand Up @@ -412,7 +420,7 @@ menu_option_14() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
echo "Done."
}
Expand Down Expand Up @@ -471,7 +479,7 @@ menu_option_16() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
echo "Done."
}
Expand Down Expand Up @@ -501,7 +509,7 @@ menu_option_17() {
-var-file="../../vsphere.pkrvars.hcl" \
-var-file="../../build.pkrvars.hcl" \
-var-file="../../common.pkrvars.hcl" .

### All done. ###
echo "Done."
}
Expand Down Expand Up @@ -538,7 +546,7 @@ until [ "$selection" = "0" ]; do
echo " / /_/ / __ / ___/ //_/ _ \/ ___/ / __ / / / / / / __ / ___/ "
echo " / ____/ /_/ / /__/ ,< / __/ / / /_/ / /_/ / / / /_/ (__ ) "
echo "/_/ \__,_/\___/_/|_|\___/_/ /_____/\__,_/_/_/\__,_/____/ "
echo ""
echo ""
echo -n " Select a HashiCorp Packer build for VMware vSphere:"
echo ""
echo ""
Expand All @@ -561,7 +569,7 @@ until [ "$selection" = "0" ]; do
echo " 12 - Windows Server 2019 - All"
echo " 13 - Windows Server 2019 - Standard Only"
echo " 14 - Windows Server 2019 - Datacenter Only"
echo " 15 - Windows Server 2016 - All"
echo " 15 - Windows Server 2016 - All"
echo " 16 - Windows Server 2016 - Standard Only"
echo " 17 - Windows Server 2016 - Datacenter Only"
echo ""
Expand Down
16 changes: 10 additions & 6 deletions builds/linux/almalinux-8/linux-almalinux.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
DESCRIPTION:
DESCRIPTION:
AlmaLinux 8 template using the Packer Builder for VMware vSphere (vsphere-iso).
*/

Expand Down Expand Up @@ -82,11 +82,15 @@ source "vsphere-iso" "linux-almalinux" {
shutdown_timeout = var.common_shutdown_timeout

// Communicator Settings and Credentials
communicator = "ssh"
ssh_username = var.build_username
ssh_password = var.build_password
ssh_port = var.communicator_port
ssh_timeout = var.communicator_timeout
communicator = "ssh"
ssh_proxy_host = var.communicator_proxy_host
ssh_proxy_port = var.communicator_proxy_port
ssh_proxy_username = var.communicator_proxy_username
ssh_proxy_password = var.communicator_proxy_password
ssh_username = var.build_username
ssh_password = var.build_password
ssh_port = var.communicator_port
ssh_timeout = var.communicator_timeout

// Template and Content Library Settings
convert_to_template = var.common_template_conversion
Expand Down
27 changes: 26 additions & 1 deletion builds/linux/almalinux-8/variables.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
DESCRIPTION:
DESCRIPTION:
AlmaLinux 8 variables using the Packer Builder for VMware vSphere (vsphere-iso).
*/

Expand Down Expand Up @@ -293,6 +293,31 @@ variable "build_key" {
sensitive = true
}

variable "communicator_proxy_host" {
type = string
description = "A SOCKS proxy host to use for SSH connection."
default = null
}

variable "communicator_proxy_port" {
type = number
description = "A port of the SOCKS proxy."
default = null
}

variable "communicator_proxy_username" {
type = string
description = "The optional username to authenticate with the proxy server."
default = null
}

variable "communicator_proxy_password" {
type = string
description = "The optional password to use to authenticate with the proxy server."
sensitive = true
default = null
}

variable "communicator_port" {
type = string
description = "The port for the communicator protocol."
Expand Down
16 changes: 10 additions & 6 deletions builds/linux/centos-linux-8/linux-centos-linux.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
DESCRIPTION:
DESCRIPTION:
CentOS Linux 8 template using the Packer Builder for VMware vSphere (vsphere-iso).
*/

Expand Down Expand Up @@ -82,11 +82,15 @@ source "vsphere-iso" "linux-centos-linux" {
shutdown_timeout = var.common_shutdown_timeout

// Communicator Settings and Credentials
communicator = "ssh"
ssh_username = var.build_username
ssh_password = var.build_password
ssh_port = var.communicator_port
ssh_timeout = var.communicator_timeout
communicator = "ssh"
ssh_proxy_host = var.communicator_proxy_host
ssh_proxy_port = var.communicator_proxy_port
ssh_proxy_username = var.communicator_proxy_username
ssh_proxy_password = var.communicator_proxy_password
ssh_username = var.build_username
ssh_password = var.build_password
ssh_port = var.communicator_port
ssh_timeout = var.communicator_timeout

// Template and Content Library Settings
convert_to_template = var.common_template_conversion
Expand Down
27 changes: 26 additions & 1 deletion builds/linux/centos-linux-8/variables.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
DESCRIPTION:
DESCRIPTION:
CentOS Linux 8 variables using the Packer Builder for VMware vSphere (vsphere-iso).
*/

Expand Down Expand Up @@ -293,6 +293,31 @@ variable "build_key" {
sensitive = true
}

variable "communicator_proxy_host" {
type = string
description = "A SOCKS proxy host to use for SSH connection."
default = null
}

variable "communicator_proxy_port" {
type = number
description = "A port of the SOCKS proxy."
default = null
}

variable "communicator_proxy_username" {
type = string
description = "The optional username to authenticate with the proxy server."
default = null
}

variable "communicator_proxy_password" {
type = string
description = "The optional password to use to authenticate with the proxy server."
sensitive = true
default = null
}

variable "communicator_port" {
type = string
description = "The port for the communicator protocol."
Expand Down
Loading