Skip to content

Commit

Permalink
Support ssh_proxy_* variables for Linux images (#40)
Browse files Browse the repository at this point in the history
* Update README.md

* Add proxy.pkrvars.hcl

* Add proxy variables in Linux sources

Signed-off-by: Stéphane Este-Gracias <[email protected]>

Co-authored-by: Ryan Johnson <[email protected]>
  • Loading branch information
sestegra and Ryan Johnson authored Sep 25, 2021
1 parent b45eeb6 commit 6189c92
Show file tree
Hide file tree
Showing 19 changed files with 346 additions and 73 deletions.
68 changes: 45 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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 @@ -255,27 +256,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 @@ -291,6 +286,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 @@ -309,6 +327,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 @@ -317,14 +347,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
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
14 changes: 9 additions & 5 deletions builds/linux/almalinux-8/linux-almalinux.pkr.hcl
Original file line number Diff line number Diff line change
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
25 changes: 25 additions & 0 deletions builds/linux/almalinux-8/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,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
14 changes: 9 additions & 5 deletions builds/linux/centos-linux-8/linux-centos-linux.pkr.hcl
Original file line number Diff line number Diff line change
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
25 changes: 25 additions & 0 deletions builds/linux/centos-linux-8/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,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
14 changes: 9 additions & 5 deletions builds/linux/centos-stream-8/linux-centos-stream.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ source "vsphere-iso" "linux-centos-stream" {
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
Loading

0 comments on commit 6189c92

Please sign in to comment.