Skip to content

Refactor Proxmox VM install scripts, add libvirt Ubuntu installer - #342

Merged
bubacoder merged 1 commit into
mainfrom
local-vm
Jun 21, 2026
Merged

Refactor Proxmox VM install scripts, add libvirt Ubuntu installer#342
bubacoder merged 1 commit into
mainfrom
local-vm

Conversation

@bubacoder

@bubacoder bubacoder commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Documentation
    • Updated setup and runbook references, plus website navigation, to reflect the new VM script directory layout.
  • New Features
    • Added Ubuntu cloud VM provisioning for libvirt using cloud-init.
  • Improvements
    • Improved offline Proxmox provisioning by syncing VM scripts to the host via rsync and running them from a temporary location (including the cloud VM workflow).
    • Refreshed the Ubuntu cloud image target to a newer release and standardized “download-only” handling.
  • Chores
    • Introduced shared VM provisioning helper logic reused across Proxmox provisioning scripts, including pre-flight VM existence checks.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: db3c2dcf-cd68-4332-ac6b-cd513356068d

📥 Commits

Reviewing files that changed from the base of the PR and between 82b2c35 and 603d4da.

📒 Files selected for processing (16)
  • AGENTS.md
  • Taskfile.yaml
  • docs/runbooks.md
  • docs/setup.md
  • docs/web/update-docs-config.yaml
  • vm/lib-common.sh
  • vm/libvirt/create-ubuntu-cloud-vm.sh
  • vm/proxmox/README.md
  • vm/proxmox/create-openwrt-vm.sh
  • vm/proxmox/create-ubuntu-cloud-vm.sh
  • vm/proxmox/create-ubuntu-server-vm.sh
  • vm/proxmox/haiku-os.md
  • vm/proxmox/macos.md
  • vm/proxmox/openwrt.md
  • vm/proxmox/ubuntu.md
  • vm/proxmox/windows.md
✅ Files skipped from review due to trivial changes (4)
  • docs/web/update-docs-config.yaml
  • AGENTS.md
  • docs/runbooks.md
  • docs/setup.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • Taskfile.yaml
  • vm/lib-common.sh
  • vm/proxmox/create-ubuntu-server-vm.sh
  • vm/libvirt/create-ubuntu-cloud-vm.sh
  • vm/proxmox/create-ubuntu-cloud-vm.sh
  • vm/proxmox/create-openwrt-vm.sh

Walkthrough

Extracts shared Bash helpers into a new vm/lib-common.sh library defining IMAGE_DIR, SNIPPETS_DIR, VM_STORAGE defaults, and five utility functions (get_authorized_keys, download_cloud_image, write_ubuntu_cloud_user_data, check_vm_not_exists, parse_download_only_arg). Adds a new vm/libvirt/create-ubuntu-cloud-vm.sh script. Refactors three existing Proxmox VM scripts to source the shared library, removing duplicate code and updating argument parsing. Updates the offline-data Taskfile task from stdin-streaming to rsync+ssh execution. Updates all documentation and configuration references to the new vm/ path layout.

Changes

VM Scripts Reorganization and Shared Library

Layer / File(s) Summary
Shared vm/lib-common.sh library
vm/lib-common.sh
New shared Bash library with strict shell options, storage defaults (IMAGE_DIR, SNIPPETS_DIR, VM_STORAGE), and five helper functions: get_authorized_keys (resolves user/home and emits SSH keys as YAML), download_cloud_image (downloads/verifies SHA256), write_ubuntu_cloud_user_data (generates cloud-init config), check_vm_not_exists (validates VM does not exist), parse_download_only_arg (parses CLI flags).
New libvirt Ubuntu cloud VM script
vm/libvirt/create-ubuntu-cloud-vm.sh
New provisioning script sourcing lib-common.sh; defines VM configuration constants, prepare_vm_disk (qcow2 convert+resize), create_cloud_init_config (user-data+meta-data), create_vm (virt-install with osinfo fallback), and a root-enforcing main flow with download-only support via --download-only flag.
Proxmox VM scripts refactored
vm/proxmox/create-openwrt-vm.sh, vm/proxmox/create-ubuntu-cloud-vm.sh, vm/proxmox/create-ubuntu-server-vm.sh
All three scripts now source ../lib-common.sh, removing duplicated storage variables, download/checksum functions, and inline --download-only parsing. create-openwrt-vm.sh adds derived CHECKSUM_URL and uses shared helpers. create-ubuntu-cloud-vm.sh bumps UBUNTU_VERSION to 26.04 and refactors cloud-init generation via write_ubuntu_cloud_user_data. create-ubuntu-server-vm.sh replaces get_authorized_keys_config with get_authorized_keys_autoinstall (resolves home via SUDO_USER/USER), updates download/checksum/VM-creation logic to use library-provided paths and validation.
Taskfile offline-data task
Taskfile.yaml
get-offline-data-proxmox now rsyncs vm/ to the Proxmox host at /tmp/vm/ and executes the three provisioning scripts remotely via ssh bash /tmp/vm/... --download-only, replacing the previous stdin-streaming approach.
Docs and config path updates
AGENTS.md, docs/runbooks.md, docs/setup.md, docs/web/update-docs-config.yaml
All references updated from proxmox/ to vm/proxmox/ or vm/; docs/setup.md also adds a new rsync+ssh example block for running the Ubuntu Server VM script from the admin host.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • bubacoder/infra#278: Directly related — refactors proxmox/create-ubuntu-cloud-vm.sh functionality that is now extracted into vm/lib-common.sh and vm/libvirt/create-ubuntu-cloud-vm.sh.
  • bubacoder/infra#126: Introduced the get-offline-data-proxmox task in Taskfile.yaml that this PR reworks from stdin-streaming to rsync+ssh execution.
  • bubacoder/infra#123: Added the "Reinstall a Docker host" runbook in docs/runbooks.md that this PR updates to reference the new vm/proxmox/ script path.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: refactoring Proxmox VM scripts and adding a new libvirt Ubuntu cloud VM installer.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch local-vm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
vm/proxmox/create-openwrt-vm.sh (1)

69-70: ⚡ Quick win

Use VM_STORAGE consistently instead of hardcoding local-lvm.

Line 69 bypasses the shared storage config from lib-common.sh, which can drift from the rest of the scripts. Use ${VM_STORAGE} here as well.

Proposed fix
-    qm set "${VMID}" --scsi0 local-lvm:0,import-from="$(realpath "./${VM_IMG}")",ssd=1
+    qm set "${VMID}" --scsi0 "${VM_STORAGE}:0,import-from=$(realpath "./${VM_IMG}"),ssd=1"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@vm/proxmox/create-openwrt-vm.sh` around lines 69 - 70, Replace the hardcoded
storage name local-lvm with the ${VM_STORAGE} variable in the qm set command on
line 69 that configures the SCSI device. Change local-lvm:0 to ${VM_STORAGE}:0
to ensure the storage configuration is consistent with the shared config from
lib-common.sh and avoid configuration drift across scripts.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/setup.md`:
- Line 32: The line containing "See [Proxmox VE]" in the setup.md file is
missing the proper Markdown blockquote prefix. The `-->` text will render as
plain text instead of creating the intended callout styling. Restore the line by
replacing the `-->` prefix with the correct Markdown blockquote prefix `>` to
enable proper formatting and visual styling for this note.

In `@vm/lib-common.sh`:
- Around line 34-41: Replace the hardcoded fixed path `/tmp/SHA256SUMS` with a
secure temporary file created using `mktemp` to prevent symlink-clobber attacks
on multi-user systems. Update the wget command that downloads to
`/tmp/SHA256SUMS` and the subsequent sha256sum verification check to use the new
temporary file path instead. Additionally, add a cleanup trap to ensure the
temporary file is removed when the script exits, even in error cases.

In `@vm/proxmox/create-ubuntu-server-vm.sh`:
- Around line 20-23: Remove the hardcoded PASSWORD_HASH variable and the comment
that documents the plaintext password creation method, as these create
predictable bootstrap credentials across all VMs. In the autoinstall
configuration section (outside the current diff range), disable password
authentication by setting allow-pw: false in the SSH configuration to prevent
password-based login. This addresses the root cause of using static credentials
while also ensuring consistency across other affected VM creation scripts that
reuse the same hash.

---

Nitpick comments:
In `@vm/proxmox/create-openwrt-vm.sh`:
- Around line 69-70: Replace the hardcoded storage name local-lvm with the
${VM_STORAGE} variable in the qm set command on line 69 that configures the SCSI
device. Change local-lvm:0 to ${VM_STORAGE}:0 to ensure the storage
configuration is consistent with the shared config from lib-common.sh and avoid
configuration drift across scripts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0186f058-dadb-4edf-a0fa-84215217e224

📥 Commits

Reviewing files that changed from the base of the PR and between f471ce9 and 309c66d.

📒 Files selected for processing (16)
  • AGENTS.md
  • Taskfile.yaml
  • docs/runbooks.md
  • docs/setup.md
  • docs/web/update-docs-config.yaml
  • vm/lib-common.sh
  • vm/libvirt/create-ubuntu-cloud-vm.sh
  • vm/proxmox/README.md
  • vm/proxmox/create-openwrt-vm.sh
  • vm/proxmox/create-ubuntu-cloud-vm.sh
  • vm/proxmox/create-ubuntu-server-vm.sh
  • vm/proxmox/haiku-os.md
  • vm/proxmox/macos.md
  • vm/proxmox/openwrt.md
  • vm/proxmox/ubuntu.md
  • vm/proxmox/windows.md

Comment thread docs/setup.md
Comment thread vm/lib-common.sh Outdated
Comment thread vm/proxmox/create-ubuntu-server-vm.sh
@bubacoder
bubacoder force-pushed the local-vm branch 2 times, most recently from 8707870 to 82b2c35 Compare June 21, 2026 08:07
@bubacoder
bubacoder merged commit ed3776b into main Jun 21, 2026
4 checks passed
@bubacoder
bubacoder deleted the local-vm branch June 21, 2026 16:47
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