2025-12-08 08:16:22 +01:00
- name : Deploy VM templates
hosts : node0
tasks :
# - name: Import variables from Ansible vault
# ansible.builtin.include_vars: secrets.yml
2025-12-08 09:29:00 +01:00
- name : Install proxmoxer from APT
apt :
name : python3-proxmoxer
state : present
update_cache : yes
2025-12-08 09:24:22 +01:00
2025-12-09 20:41:44 +01:00
- 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
2025-12-09 19:33:22 +01:00
2025-12-09 20:41:44 +01:00
- name : "[PREFLIGHT] Determine whether 'snippets' is already configured"
ansible.builtin.set_fact :
snippets_already_present : "{{ 'snippets' in snippets_check.stdout }}"
2025-12-09 19:33:22 +01:00
2025-12-09 20:41:44 +01:00
- name : "[PREFLIGHT] Ensure 'snippets' is enabled for {{ proxmox_snippets_storage }}"
2025-12-08 10:43:15 +01:00
ansible.builtin.replace :
path : /etc/pve/storage.cfg
2025-12-09 20:41:44 +01:00
regexp : '(dir:\s*{{ proxmox_snippets_storage }}[\s\S]*?content\s+)(.*)(?<!snippets)'
replace : '\1\2,snippets'
when : not snippets_already_present
2025-12-09 20:46:23 +01:00
vars :
proxmox_snippets_storage : local
2025-12-09 19:33:22 +01:00
2025-12-08 10:43:15 +01:00
- 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
2025-12-08 08:16:22 +01:00
- name : Deploy templates with proxmox_template_vm
ansible.builtin.include_role :
name : joshrnoll.homelab.proxmox_template_vm
vars :
2025-12-08 09:24:22 +01:00
2025-12-10 18:53:55 +01:00
proxmox_template_vm_supported_distros :
- fedora
- ubuntu
- debian
proxmox_template_vm_fedora_image : Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2
proxmox_template_vm_fedora_image_url : https://download.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2
proxmox_template_vm_ubuntu_image : jammy-server-cloudimg-amd64.img
proxmox_template_vm_ubuntu_image_url : https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
proxmox_template_vm_debian_image : debian-13-generic-arm64-20251117-2299.qcow2
proxmox_template_vm_debian_image_url : https://cloud.debian.org/images/cloud/trixie/20251117-2299/debian-13-generic-arm64-20251117-2299.qcow2
proxmox_template_vm_ubuntu_ostype : l26
proxmox_template_vm_fedora_ostype : l26
2025-12-10 18:58:20 +01:00
proxmox_template_vm_debian_ostype : l26
2025-12-10 18:53:55 +01:00
proxmox_template_vm_ubuntu_osvariant : ubuntu-20.04
proxmox_template_vm_debian_name : debian-template
proxmox_template_vm_debian_memory : 4096
proxmox_template_vm_debian_cores : 2
proxmox_template_vm_debian_storage : local-lvm
2025-12-08 08:16:22 +01:00
# Required to provide at least one
proxmox_template_vm_distros :
2025-12-10 18:53:55 +01:00
- debian
2025-12-08 08:16:22 +01:00
- ubuntu
# 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
2025-12-10 18:53:55 +01:00
# Optional customizations for debian
proxmox_template_vm_debian_storage : "local-lvm"
proxmox_template_vm_debian_name : debian-40-template
proxmox_template_vm_debian_memory : 2048
proxmox_template_vm_debian_cores : 1
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
2025-12-08 08:16:22 +01:00
# Optional customizations for ubuntu
2025-12-10 17:35:00 +01:00
proxmox_template_vm_ubuntu_storage : "local-lvm"
2025-12-08 08:16:22 +01:00
proxmox_template_vm_ubuntu_name : ubuntu-2204-template
proxmox_template_vm_ubuntu_memory : 4096
proxmox_template_vm_ubuntu_cores : 1
proxmox_template_vm_ubuntu_ciuser : "{{ ciuser }}" # From Ansible vault
proxmox_template_vm_ubuntu_cipassword : "{{ cipassword }}" # From Ansible vault
2025-12-08 09:24:22 +01:00
# proxmox_template_vm_ubuntu_sshkeys: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/id_rsa.pub') }}" # gets your ssh key from /home/user/.ssh/id_rsa.pub -- customize this to your needs
2025-12-08 10:16:02 +01:00
proxmox_template_vm_ubuntu_sshkeys : "{{ ssh_public_keys | join('\n') }}" # gets your ssh key from /home/user/.ssh/id_rsa.pub -- customize this to your needs
2025-12-10 17:45:32 +01:00
# proxmox_template_vm_ubuntu_vlan: 50
2025-12-08 08:16:22 +01:00
# Set to true if you have slow storage to avoid file locks
2025-12-09 19:11:16 +01:00
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 : vm-01
2025-12-09 20:51:26 +01:00
template : 9412
2025-12-09 19:11:16 +01:00
vmid : 1000
memory : 8192
cores : 2
node : node0 # The hostname of the node that the VM will be created on
ciuser : "{{ ciuser }}"
cipassword : "{{ cipassword }}"
2025-12-09 20:50:23 +01:00
# sshkeys: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
2025-12-09 19:11:16 +01:00
storage : local-lvm
disk_size : 32G
2025-12-10 19:05:48 +01:00
# vlan: 50
2025-12-09 19:11:16 +01:00
ip_address : 192.168 .2 .98 /24
gateway : 192.168 .2 .1
nameservers :
- 192.168 .2 .100
2025-12-10 17:45:32 +01:00
- 8.8 .8 .8
2025-12-09 19:11:16 +01:00
- name : vm-02
vmid : 1001
2025-12-09 20:51:26 +01:00
template : 9413
2025-12-09 19:11:16 +01:00
memory : 4096
cores : 1
node : node0 # The hostname of the node that the VM will be created on
ciuser : "{{ ciuser }}"
cipassword : "{{ cipassword }}"
2025-12-09 20:50:23 +01:00
# sshkeys: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
2025-12-09 19:11:16 +01:00
storage : local-lvm
disk_size : 64G
2025-12-10 19:05:48 +01:00
# vlan: 50
2025-12-09 19:33:22 +01:00
ip_address : 192.168 .2 .99 /24
2025-12-09 19:11:16 +01:00
gateway : 192.168 .2 .1
nameservers :
2025-12-09 19:33:22 +01:00
- 192.168 .2 .100
2025-12-10 17:45:32 +01:00
- 8.8 .8 .8