packer/readme.md

60 lines
2.4 KiB
Markdown
Raw Permalink Normal View History

2024-07-15 14:58:32 +02:00
# What does this stuff do?
Packer is a tool that can create Virtual Machine templates from code.
This repository hosts the code for a customized templates used in Siempie's home environment using the Proxmox Hypervisor.
2024-07-15 14:58:32 +02:00
More info:
https://developer.hashicorp.com/packer/docs/intro
https://developer.hashicorp.com/packer/integrations/hashicorp/proxmox/latest/components/builder/iso
2024-07-15 15:37:28 +02:00
# Inside the Template
2024-07-15 14:58:32 +02:00
Inside the template packer does:
- Install updates
- Install tools; curl, qemu-guest agent, sudo and wget.
- Install Ansible user with private key
- Clean guest (machine-id, logs, package cache, etc)
2024-07-15 14:58:32 +02:00
Other information to know:
- Template hostname: `localhost`
- packer username: `root`
2024-07-15 14:58:32 +02:00
- packer password: `packer`
| OS | VM Name | VM ID | Script |
|----|---------|-------|--------|
| Debian 12 | debian.template.siempie.internal | 10001 | scripts/debian12.sh |
| Ubuntu 24 | ubuntu.template.siempie.internal | 10002 | scripts/ubuntu24.sh |
2024-07-15 14:58:32 +02:00
2024-07-15 15:37:28 +02:00
# Create packer user and role on Proxmox
```
pveum role add packer -privs "Datastore.AllocateSpace Datastore.Audit Pool.Allocate Sys.Audit Sys.Console Sys.Modify VM.Allocate VM.Audit VM.Clone VM.Config.CDROM VM.Config.Cloudinit VM.Config.CPU VM.Config.Disk VM.Config.HWType VM.Config.Memory VM.Config.Network VM.Config.Options VM.Console VM.Migrate VM.Monitor VM.PowerMgmt SDN.Use"
2024-07-15 15:37:28 +02:00
pveum user add packer@pve --password <super-secure>
pveum aclmod / -user packer@pve -role packer
```
2024-07-15 14:58:32 +02:00
# Install packer
2024-07-15 15:37:28 +02:00
Install packer on your system (or dedicated pxc container):
2024-07-15 14:58:32 +02:00
https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli
# Variables
Copy the `variables.pkrvars.hcl.example` file to `variables.pkrvars.hcl` and change the variables.
# Initialize the project and install the proxmox provider
This will initialize packer and install the required proxmox plugin.
2024-07-15 14:58:32 +02:00
```
packer init -var-file variables.pkrvars.hcl ubuntu24/packer.pkr.hcl
```
# Customization
Since packer allows either an inline or a script execution there is a script per template.
See the table above for the specific location per template.
2024-07-15 14:58:32 +02:00
# Usage
Debian 12 Template:
```
packer build -force -var-file variables.pkrvars.hcl debian12/packer.pkr.hcl
```
Ubuntu 24 Template:
2024-07-15 14:58:32 +02:00
```
packer build -force -var-file variables.pkrvars.hcl ubuntu24/packer.pkr.hcl
```
Note: the `-force` flag removes an already existing VM or Template with the same ID (999).