From ecc1216aeb62a7184df12806915cc65193dec8c5 Mon Sep 17 00:00:00 2001 From: Christophe Jauffret Date: Mon, 27 Feb 2023 08:50:10 +0100 Subject: [PATCH] add ubuntu example (#110) --- README.md | 2 +- example/README.md | 5 +++- ...d.centos.pkr.hcl => build.nutanix.pkr.hcl} | 17 +++++------ example/init/plugin.pkr.hcl | 2 +- example/source.nutanix.pkr.hcl | 29 +++++++++++++++++++ example/variables.pkr.hcl | 4 +++ 6 files changed, 46 insertions(+), 13 deletions(-) rename example/{build.centos.pkr.hcl => build.nutanix.pkr.hcl} (72%) diff --git a/README.md b/README.md index b0405b4..085a627 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Then, run [`packer init`](https://www.packer.io/docs/commands/init). packer { required_plugins { nutanix = { - version = ">= 0.1.3" + version = ">= 0.5.0" source = "github.com/nutanix-cloud-native/nutanix" } } diff --git a/example/README.md b/example/README.md index c4cb994..ff4680b 100644 --- a/example/README.md +++ b/example/README.md @@ -2,9 +2,12 @@ Validate Manifests: packer validate . -Creating from Image and running Provisioner: +Creating CentOS from local Image and running Provisioner: packer build -only nutanix.centos . +Creating Ubuntu from Upstream Image and running Provisioner: +packer build -only nutanix.ubuntu . + Creating from ISO with Kickstart-File: packer build -only nutanix.centos-kickerstart . diff --git a/example/build.centos.pkr.hcl b/example/build.nutanix.pkr.hcl similarity index 72% rename from example/build.centos.pkr.hcl rename to example/build.nutanix.pkr.hcl index ac92822..b9499fe 100644 --- a/example/build.centos.pkr.hcl +++ b/example/build.nutanix.pkr.hcl @@ -3,15 +3,20 @@ build { "source.nutanix.centos" ] + source "nutanix.ubuntu" { + name = "ubuntu" + } + source "nutanix.centos-kickstart" { name = "centos-kickstart" } + source "nutanix.windows" { name = "windows" } provisioner "shell" { - only = ["nutanix.centos"] + only = ["nutanix.centos", "nutanix.centos-kickstart" ,"nutanix.ubuntu"] environment_vars = [ "FOO=hello world", ] @@ -19,15 +24,7 @@ build { "echo \"FOO is $FOO\" > example.txt", ] } - provisioner "shell" { - only = ["nutanix.centos-kickstart"] - environment_vars = [ - "FOO=hello world", - ] - inline = [ - "echo \"FOO is $FOO\" > example2.txt", - ] - } + provisioner "powershell" { only = ["nutanix.windows"] scripts = ["scripts/win-update.ps1"] diff --git a/example/init/plugin.pkr.hcl b/example/init/plugin.pkr.hcl index d4399a6..942d3ab 100644 --- a/example/init/plugin.pkr.hcl +++ b/example/init/plugin.pkr.hcl @@ -1,7 +1,7 @@ packer { required_plugins { nutanix = { - version = ">= 0.1.0" + version = ">= 0.5.0" source = "github.com/nutanix-cloud-native/nutanix" } } diff --git a/example/source.nutanix.pkr.hcl b/example/source.nutanix.pkr.hcl index 050f6ed..0633945 100644 --- a/example/source.nutanix.pkr.hcl +++ b/example/source.nutanix.pkr.hcl @@ -27,6 +27,35 @@ source "nutanix" "centos" { ssh_username = "centos" } +source "nutanix" "ubuntu" { + nutanix_username = var.nutanix_username + nutanix_password = var.nutanix_password + nutanix_endpoint = var.nutanix_endpoint + nutanix_port = var.nutanix_port + nutanix_insecure = var.nutanix_insecure + cluster_name = var.nutanix_cluster + os_type = "Linux" + + vm_disks { + image_type = "DISK_IMAGE" + source_image_uri = var.ubuntu_disk_image_name + disk_size_gb = 40 + } + + vm_nics { + subnet_name = var.nutanix_subnet + } + + image_name = "ubuntu-packer-image" + force_deregister = true + user_data = "I2Nsb3VkLWNvbmZpZwp1c2VyczoKICAtIG5hbWU6IGJ1aWxkZXIKICAgIHN1ZG86IFsnQUxMPShBTEwpIE5PUEFTU1dEOkFMTCddCmNocGFzc3dkOgogIGxpc3Q6IHwKICAgIGJ1aWxkZXI6cGFja2VyCiAgZXhwaXJlOiBGYWxzZQpzc2hfcHdhdXRoOiBUcnVl" + + shutdown_command = "echo 'packer' | sudo -S shutdown -P now" + shutdown_timeout = "2m" + ssh_password = "packer" + ssh_username = "builder" +} + source "nutanix" "centos-kickstart" { nutanix_username = var.nutanix_username nutanix_password = var.nutanix_password diff --git a/example/variables.pkr.hcl b/example/variables.pkr.hcl index 9b7a82a..c8c66b9 100644 --- a/example/variables.pkr.hcl +++ b/example/variables.pkr.hcl @@ -36,6 +36,10 @@ variable "centos_disk_image_name" { type = string } +variable "ubuntu_disk_image_name" { + type = string +} + variable "windows_2016_iso_image_name" { type = string }