Skip to content

Commit af1c7e0

Browse files
author
Ryan Johnson
authored
feat: Add common option to export machine image artifacts (vmware#226)
Adds a common option to export machine image artifacts (`.ovf`,`.vmdk`, and `.mf`) to an output path. Resolves vmware#217 Signed-off-by: Ryan Johnson <[email protected]>
1 parent e12af01 commit af1c7e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+630
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* Adds CentOS 9 Stream.
1111
* Adds Rocky Linux 9.
1212
* Adds AlmaLinux OS 9.
13-
* Adds options for setting the number of video displays and the size for the video memory for both Windows 11 and 10, which is useful for virtual desktop use cases (_e.g._, Horizon). The ability to set the number of displays was added in `v1.0.6` of `packer-plugin-vsphere`.
13+
* Adds option for setting the number of video displays and the size for the video memory for both Windows 11 and 10, which is useful for virtual desktop use cases (_e.g._, Horizon). The ability to set the number of displays was added in `v1.0.6` of `packer-plugin-vsphere`.
14+
* Adds a common option to export machine image artifacts (`.ovf`,`.vmdk`, and `.mf`) to an output path.
1415
* Removes the default requirement for a trusted root authority certificate to be imported and trusted by each machine image build. This will allow project users to get started more quickly without a pre-requisite.
1516

1617
🛠️ **Refactor**:

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ The directory structure of the repository.
360360
│ │ └── main.yml
361361
│ ├── ansible.cfg
362362
│ └── main.yml
363+
├── artifacts
363364
├── builds
364365
│ ├── ansible.pkvars.hcl.example
365366
│ ├── build.pkvars.hcl.example
@@ -392,11 +393,12 @@ The directory structure of the repository.
392393

393394
The files are distributed in the following directories.
394395

395-
* **`ansible`** - contains the Ansible roles to prepare a Linux machine image build.
396-
* **`builds`** - contains the templates, variables, and configuration files for the machine image build.
397-
* **`scripts`** - contains the scripts to initialize and prepare a Windows machine image build.
398-
* **`manifests`** - manifests created after the completion of the machine image build.
399-
* **`terraform`** - contains example Terraform plans to test machine image builds.
396+
* **`ansible`** - contains the Ansible roles to prepare Linux machine image builds.
397+
* **`artifacts`** - contains the OVF artifacts created by the builds, if enabled.
398+
* **`builds`** - contains the templates, variables, and configuration files for the machine image builds.
399+
* **`scripts`** - contains the scripts to initialize and prepare Windows machine image builds.
400+
* **`manifests`** - manifests created after the completion of the machine image builds.
401+
* **`terraform`** - contains example Terraform plans to create a custom role and test machine image builds.
400402

401403
> **Warning**
402404
>
@@ -608,7 +610,7 @@ Generate a SHA-512 encrypted password for the `build_password_encrypted` using t
608610

609611
```console
610612
rainpole@photon> sudo systemctl start docker
611-
rainpole@photon> sudo docker run -it --rm alpine:latest
613+
rainpole@photon> sudo docker run -it --rm alpine:latest
612614
mkpasswd -m sha512
613615
Password: ***************
614616
[password hash]
@@ -618,7 +620,7 @@ rainpole@photon> sudo systemctl stop docker
618620
**Example**: mkpasswd using Docker on macOS:
619621

620622
```console
621-
rainpole@macos> docker run -it --rm alpine:latest
623+
rainpole@macos> docker run -it --rm alpine:latest
622624
mkpasswd -m sha512
623625
Password: ***************
624626
[password hash]
@@ -627,7 +629,7 @@ Password: ***************
627629
**Example**: mkpasswd on Ubuntu:
628630

629631
```console
630-
rainpole@ubuntu> mkpasswd -m sha-512
632+
rainpole@ubuntu> mkpasswd -m sha-512
631633
Password: ***************
632634
[password hash]
633635
```
@@ -685,6 +687,7 @@ Edit the `config/common.pkvars.hcl` file to configure the following common varia
685687

686688
* Virtual Machine Settings
687689
* Template and Content Library Settings
690+
* OVF Export Settings
688691
* Removable Media Settings
689692
* Boot and Provisioning Settings
690693

@@ -702,6 +705,10 @@ common_content_library_name = "sfo-w01-lib01"
702705
common_content_library_ovf = true
703706
common_content_library_destroy = true
704707
708+
// OVF Export Settings
709+
common_ovf_export_enabled = false
710+
common_ovf_export_overwrite = true
711+
705712
// Removable Media Settings
706713
common_iso_datastore = "sfo-w01-cl01-ds-nfs01"
707714

artifacts/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

builds/common.pkrvars.hcl.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ common_content_library_ovf = true
1616
common_content_library_destroy = true
1717
common_content_library_skip_export = false
1818

19+
// OVF Export Settings
20+
common_ovf_export_enabled = false
21+
common_ovf_export_overwrite = true
22+
1923
// Removable Media Settings
2024
common_iso_datastore = "sfo-w01-cl01-ds-nfs01"
2125

@@ -25,4 +29,4 @@ common_http_ip = null
2529
common_http_port_min = 8000
2630
common_http_port_max = 8099
2731
common_ip_wait_timeout = "20m"
28-
common_shutdown_timeout = "15m"
32+
common_shutdown_timeout = "15m"

builds/linux/almalinux/8/linux-almalinux.pkr.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ locals {
2929
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
3030
manifest_path = "${path.cwd}/manifests/"
3131
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
32+
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
3233
data_source_content = {
3334
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
3435
build_username = var.build_username
@@ -131,6 +132,19 @@ source "vsphere-iso" "linux-almalinux" {
131132
}
132133
}
133134

135+
// OVF Export Settings
136+
dynamic "export" {
137+
for_each = var.common_ovf_export_enabled == true ? [1] : []
138+
content {
139+
name = local.vm_name
140+
force = var.common_ovf_export_overwrite
141+
options = [
142+
"extraconfig"
143+
]
144+
output_directory = local.ovf_export_path
145+
}
146+
}
147+
134148
}
135149

136150
// BLOCK: build

builds/linux/almalinux/8/variables.pkr.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ variable "common_content_library_skip_export" {
209209
default = false
210210
}
211211

212+
// OVF Export Settings
213+
214+
variable "common_ovf_export_enabled" {
215+
type = bool
216+
description = "Enable OVF artifact export."
217+
default = false
218+
}
219+
220+
variable "common_ovf_export_overwrite" {
221+
type = bool
222+
description = "Overwrite existing OVF artifact."
223+
default = true
224+
}
225+
212226
// Removable Media Settings
213227

214228
variable "common_iso_datastore" {

builds/linux/almalinux/9/linux-almalinux.pkr.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ locals {
2929
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
3030
manifest_path = "${path.cwd}/manifests/"
3131
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
32+
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
3233
data_source_content = {
3334
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
3435
build_username = var.build_username
@@ -130,6 +131,19 @@ source "vsphere-iso" "linux-almalinux" {
130131
skip_import = var.common_content_library_skip_export
131132
}
132133
}
134+
135+
// OVF Export Settings
136+
dynamic "export" {
137+
for_each = var.common_ovf_export_enabled == true ? [1] : []
138+
content {
139+
name = local.vm_name
140+
force = var.common_ovf_export_overwrite
141+
options = [
142+
"extraconfig"
143+
]
144+
output_directory = local.ovf_export_path
145+
}
146+
}
133147
}
134148

135149
// BLOCK: build

builds/linux/almalinux/9/variables.pkr.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ variable "common_content_library_skip_export" {
209209
default = false
210210
}
211211

212+
// OVF Export Settings
213+
214+
variable "common_ovf_export_enabled" {
215+
type = bool
216+
description = "Enable OVF artifact export."
217+
default = false
218+
}
219+
220+
variable "common_ovf_export_overwrite" {
221+
type = bool
222+
description = "Overwrite existing OVF artifact."
223+
default = true
224+
}
225+
212226
// Removable Media Settings
213227

214228
variable "common_iso_datastore" {

builds/linux/centos/7/linux-centos.pkr.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ locals {
2929
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
3030
manifest_path = "${path.cwd}/manifests/"
3131
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
32+
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
3233
data_source_content = {
3334
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
3435
build_username = var.build_username
@@ -130,6 +131,19 @@ source "vsphere-iso" "linux-centos" {
130131
skip_import = var.common_content_library_skip_export
131132
}
132133
}
134+
135+
// OVF Export Settings
136+
dynamic "export" {
137+
for_each = var.common_ovf_export_enabled == true ? [1] : []
138+
content {
139+
name = local.vm_name
140+
force = var.common_ovf_export_overwrite
141+
options = [
142+
"extraconfig"
143+
]
144+
output_directory = local.ovf_export_path
145+
}
146+
}
133147
}
134148

135149
// BLOCK: build

builds/linux/centos/7/variables.pkr.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ variable "common_content_library_skip_export" {
209209
default = false
210210
}
211211

212+
// OVF Export Settings
213+
214+
variable "common_ovf_export_enabled" {
215+
type = bool
216+
description = "Enable OVF artifact export."
217+
default = false
218+
}
219+
220+
variable "common_ovf_export_overwrite" {
221+
type = bool
222+
description = "Overwrite existing OVF artifact."
223+
default = true
224+
}
225+
212226
// Removable Media Settings
213227

214228
variable "common_iso_datastore" {

0 commit comments

Comments
 (0)