Skip to content

Conversation

@sbrupert
Copy link

@sbrupert sbrupert commented Jun 2, 2025

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 -force flag.

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 -force flag 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:

  1. Creating single, "rolling" golden image templates.
  2. Create multiple, image templates differentiated by a build date tag, name, etc.

I believe implementing this logic by utilizing the -force flag 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:

Forces a builder to run when artifacts from a previous build prevent a build from running. The exact behavior of a forced build is left to the builder. In general, a builder supporting the forced build will remove the artifacts from the previous build. This will allow the user to repeat a build without having to manually clean these artifacts beforehand.
- Packer Commands Docs

Callouts

  1. 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)

  2. 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant