-
Notifications
You must be signed in to change notification settings - Fork 46
[Feature] Add '-force' support for templates #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hello Steven, Thank a lot for the PR. It comes with a very good explanation, which helped me a lot to understand your context, need and goal. I agree that having a way to continuously rebuild golden image template is a nice to have. I think it would benefit not only homelabers (like you and I) but also our customers with bigger infra, teams and needs. I went through the code, and it looks good to me. How much did you test this PR since you sent it a few months ago? @AtaxyaNetwork could you take a look a this PR ? |
|
I just read the code, didn't have time to test it yet.
I need to compile and test some build before giving a go. But I like this feature, it can be very useful, especially for CI ! |
|
Hello Nathanael, Thank you for the kind words! I have not tested my changes on top of latest from the project. I'm going to rebase my work with the latest changes and re-test to confirm that everything still works as intended. @AtaxyaNetwork, Thank you for the feedback! I'll convert this PR to a draft while I get those implemented! |
7d0b68c to
4a746ce
Compare
|
Super @sbrupert thanks for the rebase, and your coming tests, I'm looking forward to read the results! |
|
Thanks @nathanael-h! Ok so I've rebased and made some changes based on the feedback received from @AtaxyaNetwork:
Both files have now been consolidated into
The code has been updated to prefer looking up the VM by UUID. If the UUID is unavailable or the lookup fails, we proceed with the traditional method of looking up by name. I was able to confirm the Without the
With
Please let me know if you guys have any questions or would like any adjustments, I'm happy to iterate. Thanks again for the review and feedback! |
|
Thanks @sbrupert for the update ! |
|
Hi ! So I just finished For me, we can merge this. |


Hello! Hope everyone's having a pleasant start to the week :)
Change Summary
This PR adds logic to template handling based on the usage of Packer's
-forceflag.If the force flag is used, the builder will replace/delete any templates with the same name as the current builds "vm_name" parameter.
If the force flag is not used, a new template will be created every time the builder is run.
Why These Changes?
I'm slowly migrating to XCP-NG in my HomeLab, and part of that process is checking out the support for the various IaC tools I'm used to with vSphere (Packer, Terraform, Ansible, etc).
I use Packer with vSphere to create "rolling" templates for the various OS's I use. This reduces the amount of time it takes to setup a VM cloned from the template, since it's always got the latest updates and patches.
I found that this XCP-NG builder works a bit differently than I and other users of the vSphere ISO builder are used to when it comes to managing existing templates.
vSphere does not allow templates with duplicate names using Packer, in which case you are required to use the
-forceflag to permit the builder to remove the old template before creating the new one. This behavior allows one to create "rolling" or "golden image" templates as I and other's are used to (PR #75)Since XCP-NG does allow you to have multiple templates with the same name, I wanted my changes to allow for both workflows:
I believe implementing this logic by utilizing the
-forceflag is appropriate since it's simple (already implemented by packer upstream, don't have to add new variables/parameters, users are already familiar with the flag's purpose/logic). Additionally, this implementation adheres to Packer's own documentation regarding the purpose and usage of the -force flag:Callouts
This PR only implements logic regarding the -force flag for templates. The XVA image creation logic was not touched. This is technically an inconsistency with the force flag logic since the XVA images seem to use their own logic for handling artifact creation (
format,skip_set_template)I am not a programmer by trade (DevOps/Sysadmin here 👋🏻) and most of my amateur experience is in Python. I thought this was a great excuse to learn some Golang and finally make my first contribution to an open source project 😄
With that being said, comments, questions, and concerns are absolutely welcome!
Cheers!