Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Turnkey Packer templates for downloading Debian, Fedora, and Ubuntu images on Proxmox (PVE) and creating PVE templates.

License

NotificationsYou must be signed in to change notification settings

trfore/packer-proxmox-templates

Repository files navigation

Turnkey Packer templates for downloading Debian, Fedora, and Ubuntu images on Proxmox (PVE) and creating PVE templates -see below for details onCentOS.

# create a SSH key for Packerssh-keygen -o -a 100 -t ed25519 -f~/.ssh/packer_id_ed25519 -C"Packer"# clone the repo & cd into itgit clone https://github.com/trfore/packer-proxmox-templates.gitcd packer-proxmox-templates# initialize packerpacker init common/.# choose a distrocd ubuntu# create the PVE templatespacker build \-var='pve_api_url=https://pve.example.com/api2/json' \-var='pve_node=pve' \-var='pve_username=packer@pve!token' \-var='pve_token=782a7700-4010-4802-8f4d-820f1b226850' \.

NOTE: Thedefault user is the distributions name, e.g.ubuntu, with the exception of CentOS beingcloud-user. Cloud-init will create a default user on all cloned VMs,must add SSH key(s) and/or password in the Proxmox GUI cloud-init settings to access the VM - SSH onlyaccepts key based authentication. All images havecloud-init,openssh-server andqemu-guest-agent installed.

NOTE: All images are built using only theroot user,no default users are created during the build. We suggestcreating a temporary SSH key-pair for Packer to use, i.e.packer_id_ed25519. This key is removed from therootaccount prior to finishing the build. After the build,root SSH access is disabled.

ssh-keygen -o -a 100 -t ed25519 -f~/.ssh/packer_id_ed25519 -C"Packer"

Repo Layout

  • Common files are stored incommon/, with each distribution folder containing symlinks to these files.

  • cloud-init, kickstart, and preseed configurations are stored within theconfigs/ folder and aredistribution-specific.

  • Thetemplate/ folder is useful for generating new build configurations, as it:

    • Contains symlinks to the common files.
    • Antemplate.auto.pkrvars.hcl file for overwriting the default variable values.
      • Note: If you clone or fork this repo,.gitignore is set to ignore other.auto.pkrvars.hcl files.
    • An example build section intemplate.pkr.hcl with multiple approaches.

Grant Packer Access to Proxmox

# create rolepveum role add PackerUser --privs"Datastore.AllocateSpace Datastore.AllocateTemplate Datastore.Audit Sys.Audit 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.Monitor VM.PowerMgmt"# create grouppveum group add packer-users# add permissionspveum acl modify / -group packer-users -role PackerUser# create user 'packer'pveum useradd packer@pve -groups packer-users# generate a tokenpveum user token add packer@pve token -privsep 0

The last command will output a token value similar to the following:

┌──────────────┬──────────────────────────────────────┐│ key          │ value                                │╞══════════════╪══════════════════════════════════════╡│ full-tokenid │ packer@pve!token                     │├──────────────┼──────────────────────────────────────┤│ info         │ {"privsep":"0"}                      │├──────────────┼──────────────────────────────────────┤│ value        │ 782a7700-4010-4802-8f4d-820f1b226850 │└──────────────┴──────────────────────────────────────┘

Packer Commands

Initialize Packer:

packer init common/.

With the symlinked common files, Packer commands work within each linux folder:

cd ubuntupacker fmt.packer init.packer validate.

Distro folders typically contain multiple images, you can limit the build by adding the-except= or-only= flag.Example passing Proxmox credentials:

cd ubuntu# build all imagespacker build \-var='pve_api_url=https://pve.example.com/api2/json' \-var='pve_node=node01' \-var='pve_username=packer@pve!token' \-var='pve_token=782a7700-4010-4802-8f4d-820f1b226850' \.# build a single imagepacker build \-var='pve_api_url=https://pve.example.com/api2/json' \-var='pve_node=node01' \-var='pve_username=packer@pve!token' \-var='pve_token=782a7700-4010-4802-8f4d-820f1b226850' \-only=proxmox-iso.ubuntu20 \.

Important Variables

All variables can be redefined using a*.auto.pkrvars.hcl file, see example file:template.auto.pkrvars.hcl.Reminder:.gitignoreis set to ignore other.auto.pkrvars.hcl files, so storing your personal values in a new file,ubuntu.auto.pkrvars.hcl, inside each distribution's directory will be ignored by git.

VariableDefaultDescriptionRequiredPlugin Variable Equivalent
pve_api_urlString, Proxmox URLYesproxmox_url
pve_nodepveString, Proxmox target node for ISOs and templatesYesnode
pve_usernameString, Proxmox username for PackerYesusername
pve_tokenString, Proxmox token value for PackerYestoken
iso_download_pvetrueBoolean, All ISOs are downloaded to ProxmoxNo
cloud_inittrueBoolean, Attach a cloud-init driveNocloud_init
cloud_init_storage_poollocal-lvmString, Proxmox storage pool to use for cloud-init driveNocloud_init_storage_pool
scsi_controllervirtio-scsi-pciString, SCSI controller modelNo
disk_typescsiString, Storage bus/deviceNotype
disk_storage_poollocal-lvmString, Storage pool nameNostorage_pool
disk_cache_modewritebackString, Storage cache modeNocache_mode
disk_discardfalseBoolean, Enable Discard/TRIM supportNodiscard
disk_ssdfalseBoolean, Enable SSD emulationNossd
net_bridgevmbr0String, NIC nameNobridge
net_modelvirtioString, NIC typeNomodel
net_vlan_tag1String, NIC VLAN tagNovlan_tag

SSH

NOTE: We suggest creating a temporary SSH key-pair for Packer to use during the build, i.e.packer_id_ed25519. This key is removed from theroot accountprior to finishing the build. Alternatively, you can use a pre-existing key and set:ssh_keypair_name,ssh_private_key_file andssh_public_key_file.Example key generation:

ssh-keygen -o -a 100 -t ed25519 -f~/.ssh/packer_id_ed25519 -C"Packer"
VariableDefaultDescriptionRequired
ssh_usernamerootString, SSH user for Packer build, used by SSH communicatorNo
ssh_passwordpasswordString, SSH user password for Packer build (Debian only)No
ssh_timeout20mString, Packer SSH timeoutNo
ssh_clear_authorized_keystrueBoolean, Remove the Packer SSH key from/root/.ssh/authorized_keysNo
ssh_keypair_namepacker_id_ed25519String, SSH key name for Packer to useYes
ssh_private_key_file~/.ssh/packer_id_ed25519String, Private SSH key for PackerYes
ssh_public_key_file~/.ssh/packer_id_ed25519.pubString, Public SSH key for PackerYes

VM IDs

VM IDs,vm_id, default to0 and will use the next free value from Proxmox. If you would like to fix these valuescreate a*.auto.pkrvars.hcl within each OS folder (HCL type:map(numeric)):

// ubuntu.auto.pkrvars.hclvm_id={"ubuntu20"=9020"ubuntu22"=9022"ubuntu24"=9024}

Other Variables

Seeiso-vars.pkr.hcl andpve-vars.pkr.hcl

Distro Configurations

CentOS

  • Thedefault user iscloud-user, update theusername,ssh key(s), and/orpassword using the Proxmoxcloud-init GUI.

  • CentOS kickstart file (link)

  • Important: CentOS URLs and checksums are intentionally not provided, as bandwidth is limited and ISOs are notavailable frommirror.centos.org. To set a mirror create an auto vars file,centos/centos.auto.pkrvars.hcl, andadd the closest geographic mirror from the list:CentOS 9 Stream Mirrors orFedora Mirror Manager. Alternatively,create your own installation tree:CentOS Docs - Creating Installation Sources for Kickstart.

    VariableDefaultDescriptionRequired
    iso_url''Map(string), URLYes
    iso_checksum''Map(string), prepend URL withfile:Yes
    centos_install_url''Map(string), URL - single source, not a mirror listYes
    centos_mirror_appstream''Map(string), URL - mirror list, if set packages will be updated on installNo
    centos_mirror_baseos''Map(string), URL - mirror list, if set packages will be updated on installNo
    centos_mirror_extras''Map(string), URL - mirror list, if set packages will be updated on installNo
    // centos.auto.pkrvars.hclcentos_install_url={"centos8"="https://mirror.example.com/centos/8-stream/BaseOS/x86_64/os/""centos9"="https://mirror.example.com/centos-stream/9-stream/BaseOS/x86_64/os/"}iso_url={"centos8"="https://mirror.example.com/centos/8-stream/isos/x86_64/CentOS-Stream-8-x86_64-latest-boot.iso""centos9"="https://mirror.example.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-boot.iso"}iso_checksum={"centos8"="file:https://mirror.example.com/centos/8-stream/isos/x86_64/CHECKSUM""centos9"="file:https://mirror.example.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-boot.iso.MD5SUM"}

Fedora

  • Thedefault user isfedora, update theusername,ssh key(s), and/orpassword using the Proxmoxcloud-init GUI.

  • Fedora kickstart file (link)

  • Note: Kickstart files arestored on the image at/root/*-ks.cfg

  • Installed packages are based on the groupserver-product-environment, consisting of:

    • Groups:core,server-product,standard
    • Packages:qemu-guest-agent
    • Excluding:
      • container-management: buildah, CNI and podman
      • hardware-support: Intel wireless cards (incore), Thunderbolt, Marvell and Netronome NICs
      • headless-management: cockpit pkgs and openssh-server
    $ dnf group info server-product-environmentEnvironment Group: ServerDescription: An integrated, easy-to-manage server.Mandatory Groups:  Container Management  Core  Hardware Support  Headless Management  Server product core  Standard...

Debian

  • Thedefault user isdebian, update theusername,ssh key(s), and/orpassword using the Proxmoxcloud-init GUI.
  • Debian preseed file (link)

Ubuntu

  • Thedefault user isubuntu, update theusername,ssh key(s), and/orpassword using the Proxmoxcloud-init GUI.

  • Ubuntu cloud-config file (link)

  • Settingapt_proxy_http and/orapt_proxy_https, creates a proxy file at/etc/apt/apt.conf.d/90curtin-aptproxy.Set using format:"https://[[user][:pass]@]host[:port]/", also possible to set value of"DIRECT" when usingApt-Cacher NG.

    VariableDefaultDescriptionRequired
    apt_proxy_http''String, APT proxy URL for Ubuntu. Default value skips setting proxyNo
    apt_proxy_https''String, APT proxy URL for Ubuntu. Default value skips setting proxyNo
  • Result of settingapt_proxy_http="http://192.168.100.2:3142" andapt_proxy_https="DIRECT":

    # /etc/apt/apt.conf.d/90curtin-aptproxyAcquire::http::proxy"http://192.168.100.2:3142";Acquire::https::proxy"DIRECT";

Maintainers & License

Taylor Fore(@trfore)

SeeLICENSE File

References

Blog Post:

Packer:

CentOS:

Debian:

Fedora:

Ubuntu:

About

Turnkey Packer templates for downloading Debian, Fedora, and Ubuntu images on Proxmox (PVE) and creating PVE templates.

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp