HashiCorp Packer to Build a Ubuntu 22.04 Image in VMware vSphere

preview_player
Показать описание
Learn how to use HashiCorp #Packer to automate the creation of #Ubuntu 22.04 Image Templates in VMware #vsphere.

In this video, we'll see how to automate the creation of a Ubuntu 22.04 VMware template with Packer. In a subsequent video, we will see how to use Terraform to provision VMs by cloning this VMware template.

## Pre-requisites

The following is required to follow along:

- Access to a vSphere instance (tested on vSphere v6.7)

▬▬▬▬▬▬ T I M E S T A M P S ⏰ ▬▬▬▬▬▬
00:00 - Introduction
00:32 - Demo Starts
01:46 - Main Packer File
06:36 - Variable Files
08:21 - user-data
09:43 - Provisioning Scripts
11:41 - Packer Build Done
12:08 - Create VM from Template
13:53 - Test the VM
14:59 - Closing Remarks

▬▬▬▬▬▬▬▬ Useful Links 🛠 ▬▬▬▬▬▬▬

▬▬▬▬▬▬▬▬▬ Courses 🎓 ▬▬▬▬▬▬▬▬
🎟️ Get 15% off of my Terraform 101 Course with this coupon ► YOUTUBE15TF101
🎟️ Get 15% off of my Vault 101 Course with this coupon ► YOUTUBE15VAULT101
▬▬▬▬▬▬▬▬ Community 🌎 ▬▬▬▬▬▬▬▬▬

▬▬▬▬▬▬▬▬ Connect 👋 ▬▬▬▬▬▬▬▬▬
Рекомендации по теме
Комментарии
Автор

Is there a reference somewhere of which network ports need to be open between Packer and VCenter? I'm in an enterprise environment and the corporate security people require details. Also, I gather the VM Packer creates while building the image will need port 80 open on the Packer server from whichever VLAN the VM is in. Is there anything else?

kmcgregoyt
Автор

Thanks a lot sharing this excellent stuff. Could you please give me a hint, how to configure a special partitionlayout using lvm within cloudinit. Kind regards, Oliver

olivergaida
Автор

So, you add your local machines public ssh-key to the cloud-init user-data file?

hereallyfast
Автор

Hi Sam. Superb video, really. Great documentation and you are a good speaker. You really seem to know your stuff.

I am getting stuck on "waiting for ssh" in Packer. Meanwhile, the VM has run through the package installs, and lets me log in to it if I use the vSphere console. Trying to use SSH from a terminal doesn't work, however, resulting in a "resource temporarily not available". On the VM, if I check with systemctl, I can see that the SSH server is active.

The last lines on the console are the printing out of the SSH host fingerprints, then some cloud-init warning about having to use a fallback datasource, and then two success messages which say "finished execute cloud user/final scripts and "reached target cloud-init target". This is where it stops doing anything, and as I said, I can now log in on the console, and use the machine. But Packer remains stuck on waiting for ssh. After some 20-30 minutes, it says it can't connect and asks me what to do. If I hit "retry", the machine remains up. But it never connects.

Any clue?

JoeriPelgrims
Автор

I'v got an error 'subiquity/Keyboard... unknown layout "en"'' or smth like that. Fixed by changing in http/user-data layout: us ; variant: ''

ctyjiuh
Автор

I have got this working however it seems that I had to modify the userdata file for locale for it to work, I am using the 22.04.2 iso file, the problem is that it seems to have an issue with the grub commands in the clean up script and when you clone the template to a vm and boot it, it boots with openssh failures and restarting the service it states it is not working.

joeharrison
Автор

Do you know about problem with language menu? my packer build works ok with ubuntu 20 but with ubuntu22, dont get language of user-data and all the time wait input in menu language

miguelcrisolrodriguez
Автор

getting error: could not find a supported CD ISO creation command (the supported commands are: xorriso, mkisofs, hdiutil, oscdimg)
solution: install mkisofs (apt install mkisofs)

mondy-chan
Автор

Just once I would like to see a video series where they start from the beginning and go to the end of a fully deployed machine. No skipping steps See YT allows people to post long videos so that's not an issue. Stand up a home lab and treat is a production environment and go through the entire process. For once I would love to see one person do such a thing.

nottad
Автор

@TeKanAid I think I have found the issue with the "Waiting for SSH..." issue. The ssh user password is not being set correctly.
Once the target machine has reached a point where it has rebooted and is waiting for Packer to login via SSH, I use my local terminal to test the ssh service. I can log in with the user/key combo to then run "sudo passwd" to change the root password. Then I used the web console to log in as root to change the "ubuntu" user password. Once I have everything matching, it continues on.
Therefore, the Packer process is not setting the "ubuntu" user password to what is in the script.
Boy I hope that makes sense.

peterallen
Автор

Does the password in the variables.pkrvars and the hashed one in http/userdata need to be the same? Or is it a case of the one in the pkrvars is like an initial password and then the hashed one overwrites it during the configuration steps?

Also is it safe to assume that the hashed password is fine to go on git? Or should that file be ignored too?

keanu
Автор

I was able to create the template using the provided scripts. Thx. I do notice the network config is deployed in the 00-installer-config.yaml and not in the 50-cloud-init.yaml.
If i run your terraform script for cloning a new vm with this template, i get 2 ip's because he will write the new ip in the 50-cloud file.
How can we fix this? If packer would use the 50-cloud-init file by default, this should fix my issue. Thanks

bartvanderbiest
Автор

I see this error when build :::

Build 'vsphere-iso.this' errored after 3 seconds 557 milliseconds: ServerFaultCode:
Unexpected element tag "efiSecureBootEnabled" seen

i try choose frmware bios, efi-secure, efi but all time see this error.
Please help me

shamsinamazli
Автор

Hallo, thank you for the video. The script gets stuck while waiting for ssh. In the virtual machine created I see the installation screen where the language has to be selected, so I guess the OS installation steps are missing. Can you confirm this. how can this be fixed?

frunzasamuel
Автор

How to create an image from the existing vmware template

MuneerHussainK
Автор

please help, stuck on "waiting for ssh to become available part".

akashrajvanshi
Автор

Hi
How do I get the whole code of this video?

hrishikeshmishra
Автор

also your website:
Pending...Pls Check Your Email
when i try to view the code. and it is not sending me any emails tried multiple times already.

helloworld
Автор

This has never worked, it does not work on Vsphere 7.0.3. There is just too much they didn't think about when they went from pre-seed to cloud-init. You will be pulling your hair out. Don't do it. Use Ansible instead, its easier to use and it just works!

jackschluckbier
Автор

hmm, getting error from curtin install step: fail curtin command in-target; fail running curtin in-target -- setupcon --save-only ; fail configuring installed system / sth sth json:stagees=["curthooks"]

cant nail the actual issue, logs tell pretty much nothing - that some exception occured and a python stacktrace, without pointing at actual problem, just exit code 3. early ssh stop works, network works fine, when i enter the shell from 'an error occured' stage, can apt update, install packages fine. any hints at where to look?

ubntu-22.04.2-liveserver-iso

EDIT:
ok, turns out either canonical messed something up in 22.04.2 and iso is broken or i messed up updating your files to that version, cause i switched back to 22.04.1 included in your repo and.. it magically worked

zawiasfx