packer-plugin-proxmox icon indicating copy to clipboard operation
packer-plugin-proxmox copied to clipboard

Builders for creating/cloning containers (CTs)

Open chrisbenincasa opened this issue 2 years ago • 7 comments

Please search the existing issues for relevant feature requests, and use the reaction feature (https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to add upvotes to pre-existing requests.

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

New builders for creating and cloning CTs (containers) and / or converting them into templates

Use Case(s)

Containers are a core feature of Proxmox, alongside VMs. It would be useful to automate the creation of container templates, etc.

Potential configuration

I have a minimal working version of container creation in my fork of the plugin. I'd be happy to take a stab at implementing the new builders! The configuration I have looks like:

source "proxmox-ct" "test" {
  username                 = "${var.pve_api_token_id}"
  token                    = "${var.pve_api_token_secret}"
  proxmox_url              = "${var.pve_url}"
  node                     = "zeus"
  insecure_skip_tls_verify = true
  os_template              = "local:vztmpl/debian-11-standard_11.6-1_amd64.tar.zst"
  storage                  = "local-zfs"

  cores     = 1
  cpu_limit = 500
  memory    = 512

  network_interfaces {
    name     = "eth0"
    bridge   = "vmbr0"
    firewall = false
    ip       = "dhcp"
  }

  user_password = "${var.user_password}"

  start = true
}

build {
  sources = ["sources.proxmox-ct.test"]

  provisioner "shell" {
    inline = [
      "ls /"
    ]
  }
}

Potential References

https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/lxc https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/lxc/{vmid}/template

chrisbenincasa avatar May 06 '23 14:05 chrisbenincasa

Update on my attempt here, here's the WIP: https://github.com/hashicorp/packer-plugin-proxmox/compare/main...chrisbenincasa:packer-plugin-proxmox:ct-create?expand=1

Few notes:

  • Currently, this is able to create CT templates, very similar to how the ISO builder works for VMs
  • It requires SSH access to the Proxmox host itself, which is sort of unfortunate. This is necessary because the Proxmox API does not expose the DHCP-assigned IP addresses for a container in the same way it does for VMs that have the QEMU agent running. This is a long standing issue in Proxmox itself: https://bugzilla.proxmox.com/show_bug.cgi?id=2602
    • The provisioning method works by SSH'ing into the host and then proxying a series of pct exec commands to run inside of the container. This functionality also isn't exposed by the API
    • I'm still working on some of the more complex interactions, like uploading an entire directory into the container. pct push / pull is limited to single files and working within the confines of running these over SSH is even more limiting.

chrisbenincasa avatar May 15 '23 13:05 chrisbenincasa

This is a very good improvement , it's a must have to automate basically everything with packer

newedgex avatar Jul 26 '23 11:07 newedgex

It appears the missing piece is in APIv2 https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/lxc/{vmid}/interfaces

haxwithaxe avatar Dec 23 '23 15:12 haxwithaxe

It's been a while but if I remember correctly, that API endpoint will only return an IP address if it was statically assigned by the host node and not if DHCP was used

chrisbenincasa avatar Dec 23 '23 15:12 chrisbenincasa

I just tested with an LXC container configured to use DHCP. The API gives me the IP given by DHCP. :)

pvesh get /nodes/ank/lxc/104/interfaces --noborder
hwaddr            name inet              inet6
00:00:00:00:00:00 lo   127.0.0.1/8       ::1/128
bc:24:11:39:62:84 eth0 192.168.10.219/24 fe80::be24:11ff:fe39:6284/64

haxwithaxe avatar Dec 24 '23 01:12 haxwithaxe

Oh that's awesome! That will definitely simplify the implementation

chrisbenincasa avatar Dec 24 '23 02:12 chrisbenincasa

hey @chrisbenincasa, outstanding work you have in the PR. This is definitely a must have to build images and container templates on my homelab. Do you know if it's far from stable or it can be used as is?

emaiax avatar Oct 11 '24 16:10 emaiax