Packer: Create proxmox VM not Template

870 Views Asked by At

Can we create Proxmox virtual machine via Packer (Not a template)? Because in my case it creates a VM than stops it and makes it template. and I don't need a template I need VM

muhammadfaizanyounus@Muhammads-MacBook-Pro proxmox % packer build test3.json      
proxmox: output will be in this color.

==> proxmox: Creating VM
==> proxmox: Starting VM
==> proxmox: Waiting 3m0s for boot
==> proxmox: Typing the boot command
==> proxmox: Using ssh communicator to connect: aaa.bbb.ccc.ddd
==> proxmox: Waiting for SSH to become available...
==> proxmox: Connected to SSH!
==> proxmox: Stopping VM
==> proxmox: Converting VM to template
==> proxmox: Adding a cloud-init cdrom in storage pool local-lvm
Build 'proxmox' finished.

==> Builds finished. The artifacts of successful builds are:
--> proxmox: A template was created: 152
3

There are 3 best solutions below

1
On BEST ANSWER

that's how it is... As for me, at the end of the Packer process, I run a sed command on VM conf file to change from "Template: 1" to "Template: 0"

Regards

0
On

Thanks to Freddy Légé

It is really nice and quick way to convert template into VM and back.

I just add some notes.

VM config file is situated on pmx node itself and you should have sufficient rights to access it
For ProxmoxVE 7.2 location is /etc/pve/nodes/<node_name>/qemu-server/<vm-id>.conf

Besides I didn't see in Packer by design opportunity to execute commands on the pmx node. Only on VMs you created by Packer.

I think after VM creation you can run manually something like this:

ssh -i pmx_node_key root@node_ip sed 's/template\: 1/template\: 0/' <path_to_vm_config_file>"
0
On

Packer is a tool to create 'golden images' not VM, so I don't think it's possible.

quote from https://www.packer.io/docs

Packer is an open source tool that enables you to create identical machine images for multiple platforms from a single source template. A common use case is creating "golden images" that teams across an organization can use in cloud infrastructure.

You can look at other tools to do what you want, like Terraform (from HashiCorp too), or salt-cloud (from Saltstack/Salt project). But I think both needs an image to be used.