andif888 / packer-windows-vsphere-iso

This repo builds automatically Windows VM templates (Windows 11, Windows 10, Server 2019, Server 2022) for VMware vSphere environment using Hashicorp's Packer using freely available Windows Eval ISOs.
52 stars 17 forks source link

Packer #2

Open Weasleman opened 1 year ago

Weasleman commented 1 year ago

Let me start by saying great work. I've not used this as yet but looking to do just that. I am how ever trying to understand how your code works. I'm guessing that when you run the packer init it initialises the directory and when applied it uses the windows.pkr.hcl to start im guessing download the ISO image. Builds a VM template to the specification set in windows.pkr.hcl or over ridden variables.auto.pkrvars.hcl id left as a blank. Its at this point my brain is going in various directions on what happens. Would have DM you but no functionality. New to packer. So I will apologise for writing this here just trying to understand how the scripts work a bit more.

andif888 commented 1 year ago

that's right. windows.pcr.hcl is the main file. Any variable which is defined there can be overridden by variable assignments in variables.auto.pkrvars.hcl. Additionally any variable can be overridden by using packer's commandline parameter -var='variablename=value'. This happends exactly in the build-*.sh files, where you can find the download url for the ISO file and also autounattend.xml.

  1. Packer downloads the ISO to the defined VMware datastore
  2. Packer creates a VM and mount the ISO
  3. Packer mounts a floppy on the fly containing the scripts in the setup folder
  4. Packer Mounts a floppy containing the autounattend.xml
  5. Packer starts the VM and the ISO and autounattend.xml are doing their job.

Hope that helps.

Weasleman commented 1 year ago

I can see things in the script I was unaware of what packer is actually doing. I see lots of configuration, was not sure what's doing what. Seems packer does a lot.

Ahhh so you basically building a resource (terraform resource looks like) called windows. Then the build references the "source" called windows.

I should have followed the bread crumbs and use packer provider documentation. Was trying to break down what its doing without touching Vsphere. Will read more.

Thanks for the slight kick in the head. Appreciated you have a lot of stuff in here and stuff I need to learn.

Wintel engineer by trade with some platform experience but slowly getting into the dark side (Linux). Yes enjoying muchly.

One of the other things I'm looking at is Ansible and playbooks which I know you have some ansible stuff for me to look at.

Thanks again for getting back to me its really appreciated.

Weasleman commented 1 year ago

Sorry to mither you but I have a sort of project I am working on. I am using your code and trying to build on this.

So what am I trying to achieve.

1) Build a server within a vmware environment. (windows 2019) (Your code does this but I want to use a ISO from a datastore) So created another variable pointing for the iso_path and
iso_paths = ["${var.windows_iso_path}","${var.vmtools_iso_path}"]

iso_url = "${var.os_iso_url}"

2) Sysprep the machine using said autoanswer.xml (If the server is going to be used within a ADDS environment it needs to be syspreped unless this is done by packer?) 3) Shutdown the Machine after build 4) Using post-processors to take the machine name and use this as a template. 5) Once I have a template and deploy I'm guessing I need to reapply the autoanswer.xml file.

So this is what I want to achieve and I have so many questions and unknowns. Building on your work is all and not sure if its the right way of doing things. Any idea's

andif888 commented 1 year ago

Oh I am quite familiar with this journey. What you are trying to do is achievable and quite common.

ref 1.: LGTM ref 2.: If you need to sysprep or not depends on your deployment process. If you are like me and use terraform and the OS customization options in terrform then terraform is doing the sysprep when deploying a new VM from a VM template. In that case when the VM template is already syspreped than the deployment would fail.

As soon as I create VM templates for other hypervisors or clouds (azure, kvm, proxmox) then I am doing a sysprep in packer's post processor. And when deploying new VMs from this template, I usually have to provide an autounattend.xml in the deployment process. How to specify it is dependent on the different terraform providers for the different hypervisors or clouds.

Weasleman commented 1 year ago

Hello,

I thought as much i started with the premise of making a template that could be used by either Powercli or even ansible. But im now thinking that make I should use your code to build a vanilla install of windows. then Sysprep it using your autoattend.xml or use Terraform customisation options which will sysprep the template from reading(But only if the imagine is not pre sysprepped).

With regards to terraform I have some question around how this would work,. So I point Terraform at an instance of vSphere and say go deploy a vm for instance. I'm guessing that after I initialised and planned terraform would pick up all the machines on the vSphere instance and highlight they are not in state. At which point if i apply this would wipe out all the other machines. Yes i could import these into state. Again this is all guessing as never dealt with Terraform on premise.

Also you don't mind if I bounce my code off you? I want to learn but you know how terraform can be a mystical art and it would be nice if I could bounce ideas off you? Its a shame that Git doesn't have DM functionality.

andif888 commented 1 year ago

Oh no, your existing VMs on vSphere are not getting wipe out and you do not need to import them all into terraform state. Before you start with your own code and try to reinvent the wheel, I would suggest to work through the learing repo from hashicorp itself: https://developer.hashicorp.com/terraform/tutorials/virtual-machine/vsphere-provider I my opinion this is a good staring point and has helped me a lot.

Weasleman commented 1 year ago

Thanks for the help will take a look at that over the next couple of days. I have some knowledge of terraform but its now understanding the syntax on how to put these things together. I know I've said this but appreciate the help.

Weasleman commented 1 year ago

Hello,

I started looking at packer and it brought me to ubuntu and now I'm trying to provision a ubuntu 20.04 server to vsphere. Now I figured out that preseed.cfg has been deprecated for autoinstall. So I have created a cloud-init user-data file and its doing what its supposed to but failing on image

just wondering if you have come across this ?