Compare commits

...

79 Commits

Author SHA1 Message Date
dc52a02df7 refactor ♻️: Refactor uninstall script task to use ansible.builtin.shell instead of ansible.builtin.command
Updated the uninstall script task to use `ansible.builtin.shell` for better command execution and flexibility.
2025-12-16 21:05:38 +01:00
3c4d7d73b5 refactor ♻️: Remove unnecessary conditional check and registration in Proxmox task
Refactored the Proxmox task code by removing redundant conditional checks and registration steps, simplifying the logic and improving performance.
2025-12-16 21:02:08 +01:00
651bf323df refactor ♻️: Refactor Proxmox playbook to use ansible.builtin.expect with ignore_errors
Updated the `proxmox.yml` file to include the use of `ansible.builtin.expect` module and set `ignore_errors` to handle exceptions gracefully.
2025-12-16 21:00:08 +01:00
d7726852ea refactor ♻️: Replace PVE-mods repository cloning with direct script download and execution.
Refactored the project to eliminate the need for cloning a repository by instead downloading and executing a script directly. This simplifies the setup process and reduces dependency on external repositories.
2025-12-16 20:56:19 +01:00
6370fbad21 refactor ♻️: Refactor uninstall/install scripts to use bash
Updated the uninstall and install scripts to use bash for better compatibility across different environments.
2025-12-16 20:49:28 +01:00
2c03831394 refactor ♻️: Refactor shell to command in proxmox.yml task
Updated the task in proxmox.yml to use 'command' instead of 'shell' for better clarity and consistency.
2025-12-16 20:42:03 +01:00
6d7748a127 refactor ♻️: Refactor shell task in proxmox.yml to use 'cmd' keyword
Updated the shell task in proxmox.yml to utilize the 'cmd' keyword for better readability and consistency.
2025-12-16 20:39:02 +01:00
aa640fa23f chore 📦: Add python3-pexpect to package list
Updated the package list to include python3-pexpect for enhanced automation capabilities.
2025-12-16 20:36:04 +01:00
a08dfae843 feat : Add ignore_errors, when condition, and reset fact; update script registration
This commit introduces new functionality to include error handling, conditional execution, and state reset in scripts. It also updates the script registration process to ensure compatibility with these changes.
2025-12-16 19:55:28 +01:00
8005cd5dd7 feat : Add wait-for task to ensure Proxmox Web GUI is up before running scripts.
This commit introduces a new wait-for task that waits for the Proxmox Web GUI to be fully operational before proceeding with subsequent scripts. This ensures that all dependencies are ready, preventing potential errors during script execution.
2025-12-16 19:29:37 +01:00
ae2af0ce6c refactor ♻️: Rename task to 'Run uninstall script' and update command
Refactored the task name and updated the associated command for clarity and consistency.
2025-12-16 19:25:16 +01:00
7854c4f95c feat : Add sensor monitoring task script
Introduce a new task to execute the `pve-mod-gui-sensors.sh` script with predefined answers, enhancing system monitoring capabilities.
2025-12-16 19:21:29 +01:00
d026ef8d1b refactor ♻️: Consolidate and update pkg list
Refactored package installation process by consolidating and updating the `pkg` list to improve efficiency and maintainability.
2025-12-16 18:35:57 +01:00
0b0ef1a385 fix 🐛: Fix typo in remote_src setting
Corrected a typographical error in the configuration option 'remote_src' to ensure proper functionality.
2025-12-16 18:26:33 +01:00
a58623dfcd feat : Add remote source support for copy script
This feature allows scripts to be copied from a remote source, enhancing flexibility and scalability in deployment processes.
2025-12-16 18:24:54 +01:00
89dabc0a70 chore 📦: Add pre-installation check for git
This commit adds a step to verify that git is installed on the system before proceeding with the installation of proxmoxer. This ensures compatibility and prevents potential errors during the setup process.
2025-12-16 18:18:33 +01:00
af0298410c feat : Add new feature
This is a new feature
2025-12-16 17:43:51 +01:00
f6c9c70fcd fix 🐛: Remove secrets.yml and task comment
This commit removes the inclusion of the `secrets.yml` variables file and comments out the associated task. This simplifies the project setup and addresses potential security concerns related to storing sensitive information in the codebase. The task is now commented out, effectively disabling it without removing the code.
2025-12-14 10:03:00 +01:00
066a599d9b fix 🐛: Update admin password
This commit updates the admin password within the `testvault.yml` file to improve security.  The change ensures that unauthorized access to the test vault is prevented.  This aligns with best practices for securing sensitive configuration files.
2025-12-14 09:58:37 +01:00
8f25ef2a14 fix 🐛: Update testvault.yml
This commit updates the `testvault.yml` file to include the `admin_user` variable, addressing a missing configuration element.  Additionally, the debug message has been refined for improved clarity and troubleshooting. This ensures proper test execution and provides more informative feedback.
2025-12-14 09:57:42 +01:00
a4b6ecd9f1 fix 🐛: Include and debug secrets
This commit addresses the need to incorporate secrets from the `secrets.yml` file into the application. It includes the necessary steps for debugging and resolving any potential issues related to secret management. This ensures secure access to sensitive information during development and testing.
2025-12-14 09:48:05 +01:00
c4d6dd8f4b fix 🐛: Remove commented credentials
This commit removes commented-out Proxmox credentials variables from the testing.yml file. This resolves an issue where these variables were present, potentially exposing sensitive information during testing. The removal ensures a cleaner and more secure testing environment.
2025-12-14 07:16:08 +01:00
914d6de8b6 fix 🐛: Update Proxmox credentials
This commit updates the Proxmox credentials within the testing task file.  This ensures the testing environment can successfully authenticate with Proxmox, resolving potential connection issues.  The change improves the reliability of automated testing.
2025-12-14 07:14:16 +01:00
aa8b2375db fix 🐛: Remove Proxmox credentials comments
This commit removes commented-out variable definitions related to Proxmox credentials. These were identified as unnecessary and potentially confusing, improving code readability and reducing clutter. The removal ensures a cleaner and more focused codebase.
2025-12-14 07:05:58 +01:00
5288b88fcd fix 🐛: Update VM IP address
This commit updates the virtual machine's IP address to 192.168.2.3/24, resolving an issue with network connectivity during testing.  This change ensures proper network access for the testing environment.  The change was made to align with the latest network configuration.
2025-12-14 06:56:35 +01:00
ce8d5a7811 feat : Update playbook source and add role
This commit updates the playbook's source to utilize ansible-playbook-homelab and incorporates the ansible-role-debian_common role. The changes include updating VM names and adding a new task for deploying the Debian common role, streamlining the automation process.
2025-12-14 06:54:40 +01:00
f954fd25b3 fix 🐛: Adjust VM memory for 'dc' template
This commit updates the VM memory allocation specifically for the 'dc' template, resolving an issue where memory was misconfigured. It also removes the outdated 'vm-01' entry, streamlining the configuration and ensuring optimal performance.
2025-12-12 20:15:39 +01:00
8289e73119 chore 📦: Setup PVE-mods dependencies
This commit sets up the necessary environment for PVE-mods, including installing required packages and cloning the project repository. This ensures a clean and functional setup for further development or modification of the PVE-mods project. The changes focus on the build process and dependencies.
2025-12-11 21:10:06 +01:00
fe78fd6fe7 fix 🐛: Reduce VM disk sizes
This commit updates the Debian and Ubuntu VM templates to utilize smaller disk sizes, optimizing storage space. The changes also incorporate updated configurations for improved performance and compatibility. These adjustments streamline the VM deployment process and enhance overall system efficiency.
2025-12-11 21:09:38 +01:00
0a18c43555 fix 🐛: Update Debian image URLs
This commit updates the URLs for Debian images used as Proxmox templates. The URLs have been corrected to reflect the latest available Debian 13 images, ensuring proper template downloads and configurations within the Proxmox environment.
2025-12-10 21:03:36 +01:00
88290aaad9 docs 📝: Update documentation for VM configuration
This commit updates the documentation to reflect the changes in VM configuration, specifically regarding the `vlan` setting.  It clarifies the intended usage and potential values for this parameter. This ensures consistency and reduces potential confusion for users.
2025-12-10 19:05:48 +01:00
1472f0a2b9 fix 🐛: Update Debian OS type
Corrected the OS type for the proxmox_template_vm_debian_ostype to 'l26' to align with the latest configuration. This ensures consistency and accuracy in the template definitions. The change resolves a potential mismatch between the template and the actual operating system.
2025-12-10 18:58:20 +01:00
06ee6875e8 docs 📝: Update documentation for Debian template configurations.
This commit updates the documentation to reflect the new configurations for Debian templates, including supported distros, image URLs, and associated settings like storage, memory, cores, and SSH keys. This ensures clarity for users setting up Debian-based templates within Proxmox.
2025-12-10 18:53:55 +01:00
35424875c1 fix 🐛: Update DNS nameservers
This commit updates the DNS nameservers for two virtual machine templates (vm-01 and vm-02) to 8.8.8.8, resolving potential DNS resolution issues. This change improves network connectivity for the VMs.
2025-12-10 17:45:32 +01:00
c095c92eeb fix 🐛: Update ubuntu storage to local-lvm
This commit changes the default storage type for Ubuntu templates from 'local' to 'local-lvm'. This adjustment aligns with best practices for Ubuntu template deployments, providing a more robust and isolated storage environment for the virtual machine images.
2025-12-10 17:35:00 +01:00
d1c6c2bc99 fix 🐛: Update Ubuntu storage template
The Ubuntu template's default storage has been changed from 'hdd8t' to 'local' to align with current best practices and simplify deployment. This change ensures the template utilizes local storage, reducing potential configuration complexities. This update improves the overall usability and consistency of the template.
2025-12-10 17:33:01 +01:00
14057130e6 fix 🐛: Update VM templates
This commit updates the VM templates used during the creation process. Specifically, the 'vm-01' template is changed from 5000 to 9412, and 'vm-02' from 5500 to 9413. These changes likely reflect updated base images or configurations for the virtual machines.
2025-12-09 20:51:26 +01:00
e3414af675 style 💎: Remove commented-out sshkeys config
This commit removes a commented-out configuration section for `sshkeys` within the testing task definition. This was likely a temporary setting and is now permanently removed, simplifying the configuration and preventing potential issues.
2025-12-09 20:50:23 +01:00
5936ff6ff4 chore 📦: Update snippets storage config
This commit updates the configuration for the snippets storage, setting it to 'local'. This change ensures that snippets are stored locally, simplifying the deployment process and improving performance. The configuration update is part of a broader effort to streamline the preflight process.
2025-12-09 20:46:23 +01:00
6ef534f8d8 refactor ♻️: Preflight: Snippets configuration check
This commit refactors the preflight task to intelligently check if the 'snippets' configuration is already present in the `/etc/pve/storage.cfg` file.  It avoids redundant replacement operations and improves the preflight process by determining if the configuration is already set, preventing unnecessary modifications.
2025-12-09 20:41:44 +01:00
5faba468f7 fix 🐛: Enable snippets storage
This commit updates the PVE storage configuration to ensure the 'snippets' storage is properly enabled. It modifies the `/etc/pve/storage.cfg` file to include the 'snippets' option, resolving potential issues with snippet functionality. The IP address of the network interface has also been updated.
2025-12-09 19:33:22 +01:00
ccb9fc760c fix 🐛: Ensure snippets storage is enabled
This commit updates the `tasks/testing.yml` file to correctly enable the 'snippets' storage for Proxmox. The change ensures that the snippets storage directory is properly configured, resolving an issue where snippets were not being utilized. This update improves the Proxmox setup process and ensures snippets functionality.
2025-12-09 19:28:06 +01:00
fdc28ae4a6 fix 🐛: Ensure snippets storage is enabled
This commit updates the preflight task to correctly enable the 'snippets' storage in /etc/pve/storage.cfg. The change uses a more robust regular expression to handle potential variations in the storage configuration, ensuring the snippets feature is properly activated.
2025-12-09 19:26:38 +01:00
8b6e0a5f59 chore 📦: Update VM deployment configuration
This commit updates the Ansible role for deploying VMs, defining two new VMs with specific configurations including IP addresses, VLAN assignments, and storage options. The changes also incorporate SSH key management from a file.
2025-12-09 19:11:16 +01:00
19b568c2b8 fix 🐛: Enable snippets in storage.cfg
This commit enables the 'snippets' feature in the Proxmox storage configuration file. It achieves this by adding a snippet line to the storage.cfg, ensuring that Proxmox snippets are available.  Additionally, it creates the necessary 'snippets' directory within the specified storage path.
2025-12-08 10:43:15 +01:00
c33a1e730b fix 🐛: Update SSH key variable references to join public keys with newline in testing.yml 2025-12-08 10:16:02 +01:00
b70c32993d feat : Add task to install proxmoxer package via APT in testing.yml 2025-12-08 09:29:00 +01:00
8c8f4ff417 feat : Update SSH key variable references for Ubuntu and Fedora templates in testing.yml 2025-12-08 09:24:22 +01:00
a4597def5d fix 🐛: Correct repository URL for ansible_proxmox_vm in requirements.yml 2025-12-08 08:24:35 +01:00
cc09f270ff feat : Add deployment tasks for Proxmox VM templates with customizable options 2025-12-08 08:16:22 +01:00
8f062cca53 feat : Update requirements.yml to include additional Ansible collections 2025-12-08 07:31:11 +01:00
8527a4a4ad feat : Add additional Ansible collections to requirements.yml 2025-12-07 22:19:02 +01:00
c93f2d8ea0 feat : Add Proxmox VM role to requirements and create Debian template task 2025-12-01 19:21:00 +01:00
2928061772 refactor ♻️: Simplified container configuration and added LXC ID to template
Refactored the setupacdc.yml file to use LXC IDs instead of container IDs, simplifying the configuration process. Also updated the create_lxc_container task to use the new LXC ID format.
2025-11-09 08:35:17 +01:00
e218a1705d style 💎: Update qcow2 disk path in Proxmox template
Updated the disk path from qcow2 to qemu in the create_proxmox_debian_template.yml file. This change ensures compatibility with newer Proxmox versions.
2025-11-09 06:44:23 +01:00
d5bc7f7ea9 commit undefined: Shrink compressed qcow2 using virt-sparsify
Updated the `create_proxmox_debian_template.yml` playbook to shrink the compressed qcow2 image using virt-sparsify, replacing the original shell command. This change improves efficiency and reduces storage requirements for Proxmox VM templates.
2025-11-09 06:36:07 +01:00
adb89dc4e8 refactor ♻️: Improve file transfer from LXC container to host using pct pull
Updated the 'copy' block to use pct pull instead of pct exec and rsync, simplifying the process and reducing unnecessary commands. This change improves the efficiency and readability of the template.
2025-11-09 06:27:42 +01:00
a64aa8d848 style 💎: Update file copy commands in Proxmox Debian template
Updated the commands for copying files from the LXC container to the host, ensuring consistency and accuracy in the template. The changes also improve readability and maintainability of the template.
2025-11-08 23:23:58 +01:00
ce7291bf3c refactor ♻️: Simplify copy file from LXC container to host using pct exec
Replaced multiple commands with a single pct exec command for copying files between the LXC container and the host, improving code readability and maintainability.
2025-11-08 23:18:02 +01:00
77a5f6276a feat : Add Debian template to Proxmox VM creation task
Added a new variable to the create_proxmox_debian_template.yml file to include the Debian template, allowing for more customization in the Proxmox VM creation process.
2025-11-08 23:03:01 +01:00
cc203b3c0b style 💎: Simplify shell commands in create_proxmox_debian_template.yml
Updated shell commands to use double quotes for command arguments, improving readability and consistency.
2025-11-08 22:57:30 +01:00
4fdef98933 style 💎: Update template variables for Proxmox Debian setup
Updated the `create_proxmox_debian_template.yml` file to remove unnecessary variables and improve code readability. The changes include updating the `lxc_password` and `lxc_id` variables, making it easier to manage container IDs.
2025-11-08 22:50:56 +01:00
4cc4ad48dc refactor ♻️: Improve LXC container file management in Proxmox template
Refactored the Proxmox template to use pct commands for mounting and unmounting the LXC container filesystem, simplifying the process of copying files between containers and the host. This change improves the overall efficiency and reliability of the template.
2025-11-08 22:43:40 +01:00
aaf121cd37 style 💎: Update rsync command for LXC container to Proxmox host
Updated the rsync command to use lxc-attach -n instead of just --rsh. This change ensures that the correct SSH connection is established when copying files from the LXC container to the Proxmox host.
2025-11-08 22:27:04 +01:00
18926c0047 feat : Add new task to create Proxmox Debian template
A new task was added to the existing script to import a Debian Cloud image as a Proxmox VM template, allowing for easier deployment of Debian-based systems on Proxmox servers.
2025-11-08 22:17:59 +01:00
b4817e7706 refactor ♻️: Update LXC build container and Debian cloud image template
Refactored the tasks to improve readability, added comments for better understanding, and updated variables with new values.
2025-11-08 22:06:59 +01:00
0c60000812 refactor ♻️: Improve template copy process for better performance
Updated the Ansible task to use rsync for copying templates between LXC containers and Proxmox hosts, reducing the need for qemu-img commands. This change also includes a warning flag to prevent potential issues with lxc-attach command.
2025-11-08 21:45:54 +01:00
cb32af2ad4 style 💎: Update template synchronization mode to push
Updated the Ansible synchronize task to use a push mode instead of pull, which will ensure that the latest template is deployed on each node.
2025-11-08 21:34:16 +01:00
ffbcb2b04f style 💎: Update template to remove unnecessary delegate_to option
Updated the create_proxmox_debian_template.yml file to remove the delegate_to option, as it is no longer required. This change improves the template's simplicity and consistency.
2025-11-08 21:25:31 +01:00
c9bf893582 feat : Create Proxmox Debian template with QEMU directory
Added a new task to create the QEMU template directory on the Proxmox host, ensuring it exists and has the correct permissions. This change enables the use of the QEMU template for creating Proxmox VMs.
2025-11-08 21:20:53 +01:00
b391cd6df9 style 💎: Update rsync mode and delegate to node0
Changed the rsync mode from push to pull, and added a delegate_to parameter to specify the target node for the rsync operation.
2025-11-08 21:18:30 +01:00
2ccfc0feb2 style 💎: Update rsync opts for correct path
Updated rsync options to use the correct rsync path. This change ensures that the rsync command is executed correctly when synchronizing files.
2025-11-08 20:26:37 +01:00
1b669f701c style 💎: Update Proxmox template path
Updated the destination path for the Proxmox template to '/var/lib/vz/template/iso/' from '/var/lib/vz/template/qcow2/'. This change ensures consistency with the expected location of the ISO file.
2025-11-08 20:14:47 +01:00
c2328a22e0 style 💎: Update rsync opts for proxmox template
Updated rsync options to use the correct path for proxmox templates, ensuring proper synchronization of files.
2025-11-08 19:58:18 +01:00
c89e916351 feat : Add Proxmox Debian template with sudo installation
Added a new task to the create_proxmox_debian_template.yml file to ensure sudo is installed during the template creation process. This change allows for more secure access to the system.
2025-11-08 19:52:35 +01:00
3b512c558b style 💎: Update synchronize command to use posix module
Updated the synchronize command in the Proxmox template task to use the ansible.posix.synchronize module, which is more compatible with Proxmox's file system. This change ensures that the template can be successfully synchronized on the target host.
2025-11-08 19:24:47 +01:00
f3a2e0ad0a style 💎: Update template sync mode to pull
Updated the Ansible synchronize task in the Proxmox Debian template to use a pull mode instead of push, which is more idiomatic for synchronizing files from the host to the container.
2025-11-08 18:52:34 +01:00
3c4b4a749d style 💎: Update rsync opts for sudo rsync path
Updated rsync options to include the sudo rsync path, ensuring secure file transfer. This change aligns with best practices for secure file management in Proxmox environments.
2025-11-08 18:01:42 +01:00
9fea674cae style 💎: Update shell commands to use template variables
Updated shell commands in the create_proxmox_debian_template.yml file to use template variables for consistency and reusability. This change allows for easier management of different templates without modifying the underlying command structure.
2025-11-08 17:47:44 +01:00
10 changed files with 299 additions and 252 deletions

View File

@@ -2,4 +2,8 @@
---
collections:
# Install a collection by name
- name: community.proxmox
- name: community.proxmox
- name: community.general
- name: community.docker
- name: community.windows
- name: joshrnoll.homelab

View File

@@ -5,9 +5,20 @@
- name: ansible_samba_ad_dc
src: https://repo.piave7.duckdns.org/Jose/ansible_samba_ad_dc.git
scm: git
- name: ansible_proxmox_vm
src: https://repo.piave7.duckdns.org/Jose/ansible_proxmox_VM.git
scm: git
- name: ansible-playbook-homelab
src: https://github.com/joshrnoll/ansible-playbook-homelab.git
scm: git
# version: master # or a specific tag/branch like 'v1.0.0'
- name: ansible-role-debian_common
src: https://repo.piave7.duckdns.org/Jose/ansible-role-debian_common.git
scm: git
# - name: ansible_samba_domain_member
# src: git@repo.piave7.duckdns.org:Jose/ansible_samba_domain_member.git # <-- Use the SSH URL
# scm: git

View File

@@ -9,7 +9,7 @@
vars:
lxc_name: "debian-builder"
lxc_id: 9900
# lxc_id: 9900
lxc_storage: "local-lvm"
# lxc_storage: "hdd8t"
lxc_template: "local:vztmpl/debian-13-standard_13.1-1_amd64.tar.zst"
@@ -19,8 +19,7 @@
lxc_swap: 0
lxc_net: "name=eth0,bridge=vmbr0,ip=dhcp"
lxc_rootfs_size: "8G"
lxc_password: "password"
container_id: "{{ lxc_id }}"
lxc_password: "password"
tasks:
- block:
@@ -34,6 +33,14 @@
state: present
update_cache: true
- name: Ensure QEMU template directory exists on Proxmox host
ansible.builtin.file:
path: /var/lib/vz/template/qemu
state: directory
owner: root
group: root
mode: '0755'
- name: Combine SSH public keys into one file
ansible.builtin.copy:
dest: '{{ ssh_keys_file }}'
@@ -115,6 +122,11 @@
state: present
update_cache: true
- name: Ensure sudo is installed
ansible.builtin.apt:
name: sudo
state: present
- name: Create working directory
ansible.builtin.file:
path: "{{ workdir }}"
@@ -129,7 +141,7 @@
- name: Get QCOW2 image info
ansible.builtin.shell: qemu-img info {{ workdir }}/linux-vm.qcow2
ansible.builtin.shell: "qemu-img info {{ workdir }}/{{ image_name }}"
register: image_info
- name: Show QCOW2 image details
@@ -157,7 +169,7 @@
- name: Get QCOW2 image info
ansible.builtin.shell: qemu-img info {{ workdir }}/linux-vm.qcow2
ansible.builtin.shell: "qemu-img info {{ workdir }}/{{ image_name }}"
register: image_info
- name: Show QCOW2 image details
@@ -175,7 +187,7 @@
- name: Get QCOW2 image info
ansible.builtin.shell: qemu-img info {{ workdir }}/linux-vm.qcow2
ansible.builtin.shell: "qemu-img info {{ workdir }}/{{ template_name }}.qcow2"
register: image_info
- name: Show QCOW2 image details
@@ -185,46 +197,19 @@
{{ image_info.stdout }}
# - name: Shrink the compressed qcow2 using virt-sparsify
# ansible.builtin.shell: |
# virt-sparsify --compress {{ workdir }}/{{ template_name }}.qcow2 {{ workdir }}/{{ template_name }}_sparse.qcow2
# args:
# creates: "{{ workdir }}/{{ template_name }}_sparse.qcow2"
# - name: Get QCOW2 image info
# ansible.builtin.shell: qemu-img info {{ workdir }}/linux-vm.qcow2
# register: image_info
# - name: Show QCOW2 image details
# ansible.builtin.debug:
# msg: |
# === QCOW2 Image Info ===
# {{ image_info.stdout }}
# - name: Replace original compressed image with sparsified version
# ansible.builtin.shell: |
# mv {{ workdir }}/{{ template_name }}_sparse.qcow2 {{ workdir }}/{{ template_name }}.qcow2
# - name: Compress and shrink image
# ansible.builtin.shell: |
# qemu-img convert -O qcow2 -c {{ workdir }}/{{ image_name }} {{ workdir }}/{{ template_name }}.qcow2
# qemu-img resize {{ workdir }}/{{ template_name }}.qcow2 --shrink
- name: Copy finished template back to Proxmox host
ansible.builtin.synchronize:
src: "{{ workdir }}/{{ template_name }}.qcow2"
dest: "/var/lib/vz/template/qcow2/"
mode: push
rsync_opts:
- "--rsync-path='sudo rsync'"
- name: Import Debian Cloud image as Proxmox VM template
hosts: node0
become: true
vars_files:
- ../vars/debian_template.yml
tasks:
- block:
- name: Pull file from container to host using pct pull
command: pct pull "{{ lxc_id }}" {{ workdir }}/{{ template_name }}.qcow2 /var/lib/vz/template/qemu/{{ template_name }}.qcow2
- block:
- name: Import QCOW2 as disk to new VM
ansible.builtin.shell: >
@@ -233,7 +218,7 @@
--memory 1024
--net0 virtio,bridge=vmbr0 &&
qm importdisk {{ proxmox_template_vm_id }}
/var/lib/vz/template/qcow2/{{ template_name }}.qcow2 {{ proxmox_storage }}
/var/lib/vz/template/qemu/{{ template_name }}.qcow2 {{ proxmox_storage }}
- name: Configure VM for Cloud-Init
ansible.builtin.shell: |

View File

@@ -1,162 +0,0 @@
---
- name: Build Debian Cloud Template directly from Proxmox
hosts: node0
become: true
gather_facts: false
vars_files:
- ../vars/debian_template.yml
vars:
lxc_name: "debian-builder"
lxc_id: 9900
lxc_storage: "local-lvm"
lxc_template: "local:vztmpl/debian-13-standard_13.1-1_amd64.tar.zst"
lxc_ostype: "debian"
lxc_cores: 2
lxc_memory: 2048
lxc_net: "name=eth0,bridge=vmbr0,ip=dhcp"
lxc_rootfs_size: "8G"
tasks:
- block:
- name: Ensure build environment packages are installed on Proxmox
ansible.builtin.apt:
name:
# - libguestfs-tools
# - qemu-utils
- rsync
state: present
update_cache: true
- name: Create LXC build container
community.proxmox.lxc:
node: "{{ inventory_hostname }}"
vmid: "{{ lxc_id }}"
template: "{{ lxc_template }}"
hostname: "{{ lxc_name }}"
cores: "{{ lxc_cores }}"
memory: "{{ lxc_memory }}"
ostype: "{{ lxc_ostype }}"
net: "{{ lxc_net }}"
rootfs: "{{ lxc_storage }}:{{ lxc_rootfs_size }}"
features:
nesting: 1
state: started
register: lxc_create
ignore_errors: true
- name: Wait for LXC to boot and get IP
ansible.builtin.shell: "pct exec {{ lxc_id }} -- hostname -I | awk '{print $1}'"
register: lxc_ip
until: lxc_ip.stdout | ipaddr
retries: 20
delay: 3
- name: Add temporary LXC to in-memory inventory
ansible.builtin.add_host:
name: lxc_builder
ansible_host: "{{ lxc_ip.stdout }}"
ansible_user: root
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
when: lxc_create is changed or lxc_create is succeeded
- name: Customize Debian cloud image inside LXC
hosts: lxc_builder
become: true
vars_files:
- ../vars/debian_template.yml
tasks:
- block:
- name: Install build dependencies in LXC
ansible.builtin.apt:
name:
- qemu-utils
- libguestfs-tools
- curl
- wget
- rsync
- xz-utils
- nano
- htop
state: present
update_cache: true
- name: Create working directory
ansible.builtin.file:
path: "{{ workdir }}"
state: directory
- name: Download latest Debian genericcloud image
ansible.builtin.get_url:
url: "{{ debian_image_url }}"
dest: "{{ workdir }}/{{ image_name }}"
mode: "0644"
force: true
- name: Customize image with base utilities and root password
ansible.builtin.command: >
virt-customize -a {{ workdir }}/{{ image_name }}
--install "curl,wget,nano,rsync,htop"
--root-password password:{{ root_password }}
- name: Set DHCP identifier to hostname for cloud-init
ansible.builtin.shell: |
virt-customize -a {{ workdir }}/{{ image_name }} \
--run-command "echo 'dhcp-identifier: hostname' >> /etc/cloud/cloud.cfg.d/99_hostname.cfg"
- name: Reset machine-id
ansible.builtin.shell: |
virt-customize -a {{ workdir }}/{{ image_name }} \
--run-command 'truncate -s 0 /etc/machine-id && rm -f /var/lib/dbus/machine-id'
- name: Compress and shrink image
ansible.builtin.shell: |
qemu-img convert -O qcow2 -c {{ workdir }}/{{ image_name }} {{ workdir }}/{{ template_name }}.qcow2
qemu-img resize {{ workdir }}/{{ template_name }}.qcow2 --shrink
- name: Copy finished template back to Proxmox host
ansible.builtin.synchronize:
src: "{{ workdir }}/{{ template_name }}.qcow2"
dest: "/var/lib/vz/template/qcow2/"
mode: pull
rsync_opts:
- "--rsync-path='sudo rsync'"
- name: Import Debian Cloud image as Proxmox VM template
hosts: node0
become: true
tasks:
- block:
- name: Import QCOW2 as disk to new VM
ansible.builtin.shell: >
qm create {{ proxmox_template_vm_id }}
--name {{ template_name }}
--memory 1024
--net0 virtio,bridge=vmbr0 &&
qm importdisk {{ proxmox_template_vm_id }}
/var/lib/vz/template/qcow2/{{ template_name }}.qcow2 {{ proxmox_storage }}
- name: Configure VM for Cloud-Init
ansible.builtin.shell: |
qm set {{ proxmox_template_vm_id }} \
--scsihw virtio-scsi-pci \
--scsi0 {{ proxmox_storage }}:vm-{{ proxmox_template_vm_id }}-disk-0 \
--ide2 {{ proxmox_storage }}:cloudinit \
--boot c --bootdisk scsi0 \
--serial0 socket --vga serial0
- name: Convert VM to template
ansible.builtin.shell: "qm template {{ proxmox_template_vm_id }}"
- name: Stop and destroy LXC build container
ansible.builtin.shell: "pct stop {{ lxc_id }} && pct destroy {{ lxc_id }} --purge"
ignore_errors: true
- ansible.builtin.debug:
msg: "✅ Debian Cloud-Init template {{ template_name }} (VMID {{ proxmox_template_vm_id }}) created successfully!"

54
tasks/proxmox.yml Normal file
View File

@@ -0,0 +1,54 @@
- name: Setup Proxmox
hosts: proxmox
become: true
tasks:
- name: Ensure git is installed
ansible.builtin.apt:
pkg:
- git
- python3-proxmoxer
- lm-sensors
- python3-pexpect
state: present
update_cache: yes
cache_valid_time: 3600
- name: Download the PVE GUI sensors script
ansible.builtin.get_url:
url: https://raw.githubusercontent.com/Meliox/PVE-mods/refs/heads/main/pve-mod-gui-sensors.sh
dest: /tmp/pve-mod-gui-sensors.sh
mode: '0755' # Make it executable
- name: Run uninstall script
ansible.builtin.shell: bash /tmp/pve-mod-gui-sensors.sh uninstall
ignore_errors: true
- name: Wait for Proxmox Web GUI to be up
wait_for:
port: 8006
delay: 5
timeout: 60
- name: Reset install fact
ansible.builtin.set_fact:
pve_mod_gui_sensors_installed: null
- name: Run pve-mod-gui-sensors script with predefined answers
ansible.builtin.expect:
command: bash /tmp/pve-mod-gui-sensors.sh install
responses:
'Display temperatures for all cores \[C\] or average per CPU \[a\].*\(C/a\):.*': 'a'
'Display temperatures in Celsius \[C\] or Fahrenheit \[f\].*\(C/f\):.*': 'c'
'Enable UPS information\?.*\(y/N\):.*': 'n'
'Enable system information\?.*\(1/2/n\):.*': '2'
ignore_errors: true
- name: Wait for Proxmox Web GUI to be up
wait_for:
port: 8006
delay: 5
timeout: 60

View File

@@ -0,0 +1,11 @@
---
- name: Build Debian Template
hosts: node0
become: true
gather_facts: false
tasks:
- name: Deploy the debian template
ansible.builtin.include_role:
name: ansible_proxmox_vm

View File

@@ -30,27 +30,27 @@
node_ip: "{{ hostvars['node0']['ansible_host'] }}"
mac_address: '8E:90:31:DE:31:36'
container_id: 200
# container_template: '/var/lib/vz/template/cache/ubuntu-25.04-standard_25.04-1.1_amd64.tar.zst'
container_template: '/var/lib/vz/template/cache/debian-13-standard_13.1-1_amd64.tar.zst'
# container_template: '/var/lib/vz/template/cache/debian-12-standard_12.12-1_amd64.tar.zst'
# container_ostype: ubuntu
container_ostype: debian
container_hostname: '{{ addc_hostname }}'
container_password: '{{ addc_admin_password }}'
container_storage: local-lvm
container_rootfs_size: 8G
container_memory: 1024
container_swap: 256
container_cores: 2
container_net: name=eth0,bridge=vmbr0,ip={{ addc_ansible_host }}/24,gw={{ location_gateway }},hwaddr={{ mac_address }}
container_features: 'keyctl=1,nesting=1,mount=cifs'
container_description: default lxc
container_onboot: 1
container_protection: 0
container_unprivileged: 0
container_pubkey: '{{ ssh_public_keys[0] }}'
container_tags:
lxc_id: 200
# lxc_template: '/var/lib/vz/template/cache/ubuntu-25.04-standard_25.04-1.1_amd64.tar.zst'
lxc_template: '/var/lib/vz/template/cache/debian-13-standard_13.1-1_amd64.tar.zst'
# lxc_template: '/var/lib/vz/template/cache/debian-12-standard_12.12-1_amd64.tar.zst'
# lxc_ostype: ubuntu
lxc_ostype: debian
lxc_hostname: '{{ addc_hostname }}'
lxc_password: '{{ addc_admin_password }}'
lxc_storage: local-lvm
lxc_rootfs_size: 8G
lxc_memory: 1024
lxc_swap: 256
lxc_cores: 2
lxc_net: name=eth0,bridge=vmbr0,ip={{ addc_ansible_host }}/24,gw={{ location_gateway }},hwaddr={{ mac_address }}
lxc_features: 'keyctl=1,nesting=1,mount=cifs'
lxc_description: default lxc
lxc_onboot: 1
lxc_protection: 0
lxc_unprivileged: 0
lxc_pubkey: '{{ ssh_public_keys[0] }}'
lxc_tags:
- ansible_managed
- test
@@ -68,52 +68,52 @@
- name: debug
# Comment
ansible.builtin.debug:
msg: 'Hello world! {{ container_password }}'
msg: 'Hello world! {{ lxc_password }}'
verbosity: 0
- name: Create LXC container {{ container_hostname }} with id {{ container_id }} using pct command on shell
- name: Create LXC container {{ lxc_hostname }} with id {{ lxc_id }} using pct command on shell
ansible.builtin.shell: |
set -e
pct create {{ container_id }} {{ container_template }} \
-ostype {{ container_ostype }} \
-hostname {{ container_hostname }} \
-password '{{ container_password }}' \
pct create {{ lxc_id }} {{ lxc_template }} \
-ostype {{ lxc_ostype }} \
-hostname {{ lxc_hostname }} \
-password '{{ lxc_password }}' \
-ssh-public-keys '{{ ssh_keys_file }}' \
-cores {{ container_cores }} \
-memory {{ container_memory }} \
-swap {{ container_swap }} \
-net0 '{{container_net}}' \
-storage {{ container_storage }} \
-description '{{ container_description }}' \
-onboot {{ container_onboot }} \
-protection {{ container_protection }} \
-unprivileged {{ container_unprivileged }} \
-tags '{{ container_tags | join(',') }}' \
-features '{{ container_features }}'
-cores {{ lxc_cores }} \
-memory {{ lxc_memory }} \
-swap {{ lxc_swap }} \
-net0 '{{lxc_net}}' \
-storage {{ lxc_storage }} \
-description '{{ lxc_description }}' \
-onboot {{ lxc_onboot }} \
-protection {{ lxc_protection }} \
-unprivileged {{ lxc_unprivileged }} \
-tags '{{ lxc_tags | join(',') }}' \
-features '{{ lxc_features }}'
args:
creates: '/etc/pve/lxc/{{ container_id }}.conf'
creates: '/etc/pve/lxc/{{ lxc_id }}.conf'
no_log: false
# -password {{ container_password }} \
# -rootfs {{ container_storage }}:{{ container_id }}/vm-{{ container_id }}-disk-0.raw,size=7G \
# -password {{ lxc_password }} \
# -rootfs {{ lxc_storage }}:{{ lxc_id }}/vm-{{ lxc_id }}-disk-0.raw,size=7G \
# -timezone: {{ localization_timezone }} \
- name: Check if LXC container {{ container_hostname }} is running
- name: Check if LXC container {{ lxc_hostname }} is running
ansible.builtin.command:
cmd: pct status {{ container_id }}
cmd: pct status {{ lxc_id }}
register: pct_status
changed_when: false
- name: Start the LXC container {{ container_hostname }} if stopped
- name: Start the LXC container {{ lxc_hostname }} if stopped
ansible.builtin.command:
cmd: pct start {{ container_id }}
cmd: pct start {{ lxc_id }}
when: "'status: stopped' in pct_status.stdout"
register: start_result
changed_when: "'status: stopped' in pct_status.stdout"
- name: Wait until container has an IP address
ansible.builtin.shell: "pct exec {{ container_id }} -- hostname -I | awk '{print $1}'"
ansible.builtin.shell: "pct exec {{ lxc_id }} -- hostname -I | awk '{print $1}'"
register: lxc_ip
until: lxc_ip.stdout != ''
retries: 10

124
tasks/testing.yml Normal file
View File

@@ -0,0 +1,124 @@
---
- name: Deploy VM templates
hosts: node0
tasks:
# - name: Import variables from Ansible vault
# ansible.builtin.include_vars: secrets.yml
- name: Install proxmoxer from APT
apt:
name: python3-proxmoxer
state: present
update_cache: yes
- name: "[PREFLIGHT] Check if 'snippets' is already enabled for {{ proxmox_snippets_storage }}"
ansible.builtin.command: "grep -E 'dir:\\s*{{ proxmox_snippets_storage }}' -A5 /etc/pve/storage.cfg"
register: snippets_check
failed_when: false
changed_when: false
vars:
proxmox_snippets_storage: local
- name: "[PREFLIGHT] Determine whether 'snippets' is already configured"
ansible.builtin.set_fact:
snippets_already_present: "{{ 'snippets' in snippets_check.stdout }}"
- name: "[PREFLIGHT] Ensure 'snippets' is enabled for {{ proxmox_snippets_storage }}"
ansible.builtin.replace:
path: /etc/pve/storage.cfg
regexp: '(dir:\s*{{ proxmox_snippets_storage }}[\s\S]*?content\s+)(.*)(?<!snippets)'
replace: '\1\2,snippets'
when: not snippets_already_present
vars:
proxmox_snippets_storage: local
- name: "[PREFLIGHT] Ensure snippets storage directory exists"
ansible.builtin.file:
path: "{{ proxmox_snippets_storage_path }}/snippets"
state: directory
mode: "0755"
vars:
proxmox_snippets_storage_path: /var/lib/vz
- name: Deploy templates with proxmox_template_vm
ansible.builtin.include_role:
name: joshrnoll.homelab.proxmox_template_vm
vars:
proxmox_template_vm_supported_distros:
- fedora
- ubuntu
- debian
proxmox_template_vm_debian_image: debian-13-genericcloud-amd64-20251117-2299.qcow2
proxmox_template_vm_debian_image_url: https://cloud.debian.org/images/cloud/trixie/20251117-2299/debian-13-genericcloud-amd64-20251117-2299.qcow2
proxmox_template_vm_debian_ostype: l26
# Required to provide at least one
proxmox_template_vm_distros:
- debian
# Required proxmox credentials
proxmox_template_vm_proxmox_username: "{{ proxmox_username }}" # From Ansible vault
proxmox_template_vm_proxmox_api_token_id: "{{ proxmox_api_token_id }}" # From Ansible vault
proxmox_template_vm_proxmox_api_token_secret: "{{ proxmox_api_token_secret }}" # From Ansible vault
# Optional customizations for debian
proxmox_template_vm_debian_name: debian-template
proxmox_template_vm_debian_memory: 2048
proxmox_template_vm_debian_cores: 2
proxmox_template_vm_debian_storage: local-lvm
proxmox_template_vm_debian_ciuser: "{{ ciuser }}" # From Ansible vault
proxmox_template_vm_debian_cipassword: "{{ cipassword }}" # From Ansible vault
proxmox_template_vm_debian_sshkeys: "{{ ssh_public_keys | join('\n') }}" # gets your ssh key from /home/user/.ssh/id_rsa.pub -- customize this to your needs
# proxmox_template_vm_debian_vlan: 50
# Set to true if you have slow storage to avoid file locks
proxmox_template_vm_slow_storage: true
- name: Deploy VMs
ansible.builtin.include_role:
name: joshrnoll.homelab.create_proxmox_vms
vars:
# Proxmox credentials
create_proxmox_vms_proxmox_username: "{{ proxmox_username }}"
create_proxmox_vms_proxmox_api_token_id: "{{ proxmox_api_token_id }}"
create_proxmox_vms_proxmox_api_token_secret: "{{ proxmox_api_token_secret }}"
# VMs to be created
create_proxmox_vms_list:
- name: dc1
template: 9412
vmid: 1000
memory: 2048
cores: 2
node: node0 # The hostname of the node that the VM will be created on
ciuser: "{{ ciuser }}"
cipassword: "{{ cipassword }}"
# sshkeys: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
storage: local-lvm
disk_size: 8G
# vlan: 50
ip_address: 192.168.2.3/24
gateway: 192.168.2.1
nameservers:
- 192.168.2.100
- 8.8.8.8
- name: Test common role
hosts: dc1
tasks:
- name: Deploy VMs
ansible.builtin.include_role:
name: ansible-role-debian_common
# vars:
# # Proxmox credentials
# ansible_user: "{{ ciuser }}"
# ansible_password: "{{ cipassword }}"

17
tasks/testvault.yml Normal file
View File

@@ -0,0 +1,17 @@
---
- name: Test secrets.yml
hosts: localhost
vars:
admin_user: joseadm
admin_password: changeme
tasks:
# - name: Import variables from Ansible vault
# ansible.builtin.include_vars:
# ../../secrets.yml
- name: debug secrets.yml"
ansible.builtin.debug:
msg: "The value of the secret is {{ test_password }}"

View File

@@ -6,3 +6,6 @@ template_name: "debian-13-cloudinit-template"
root_password: "debian"
proxmox_storage: "local-lvm"
proxmox_template_vm_id: 9000
lxc_id: 9900