Update .gitignore and refactor Ubuntu template playbook to use role for Proxmox template management
This commit is contained in:
@@ -2,71 +2,15 @@
|
||||
- name: Create Ubuntu Cloud-Init Template
|
||||
hosts: proxmox
|
||||
become: yes
|
||||
|
||||
vars:
|
||||
template_id: 9000
|
||||
template_name: ubuntu-2204-cloud
|
||||
# URL for Ubuntu 22.04 Cloud Image (Jammy)
|
||||
image_url: "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
|
||||
image_name: "ubuntu-22.04-server-cloudimg-amd64.img"
|
||||
storage_pool: "local-lvm"
|
||||
memory: 2048
|
||||
cores: 2
|
||||
|
||||
# Override defaults if needed
|
||||
image_alias: ubuntu-22.04
|
||||
storage_pool: local-lvm
|
||||
|
||||
tasks:
|
||||
- name: Check if template already exists
|
||||
command: "qm status {{ template_id }}"
|
||||
register: vm_status
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
|
||||
- name: Fail if template ID exists
|
||||
fail:
|
||||
msg: "VM ID {{ template_id }} already exists. Please choose a different ID or delete the existing VM."
|
||||
when: vm_status.rc == 0
|
||||
|
||||
- name: Download Ubuntu Cloud Image
|
||||
get_url:
|
||||
url: "{{ image_url }}"
|
||||
dest: "/tmp/{{ image_name }}"
|
||||
mode: '0644'
|
||||
|
||||
- name: Install libguestfs-tools (required for virt-customize if needed, optional)
|
||||
apt:
|
||||
name: libguestfs-tools
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Create VM with hardware config
|
||||
command: >
|
||||
qm create {{ template_id }}
|
||||
--name "{{ template_name }}"
|
||||
--memory {{ memory }}
|
||||
--core {{ cores }}
|
||||
--net0 virtio,bridge=vmbr0
|
||||
--scsihw virtio-scsi-pci
|
||||
--ostype l26
|
||||
--serial0 socket --vga serial0
|
||||
|
||||
- name: Import Disk
|
||||
command: "qm importdisk {{ template_id }} /tmp/{{ image_name }} {{ storage_pool }}"
|
||||
|
||||
- name: Attach Disk to SCSI
|
||||
command: "qm set {{ template_id }} --scsi0 {{ storage_pool }}:vm-{{ template_id }}-disk-0"
|
||||
|
||||
- name: Add Cloud-Init Drive
|
||||
command: "qm set {{ template_id }} --ide2 {{ storage_pool }}:cloudinit"
|
||||
|
||||
- name: Set Boot Order
|
||||
command: "qm set {{ template_id }} --boot c --bootdisk scsi0"
|
||||
|
||||
- name: Resize Disk (Optional, e.g. 10G)
|
||||
command: "qm resize {{ template_id }} scsi0 10G"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Convert to Template
|
||||
command: "qm template {{ template_id }}"
|
||||
|
||||
- name: Remove Downloaded Image
|
||||
file:
|
||||
path: "/tmp/{{ image_name }}"
|
||||
state: absent
|
||||
- name: Run Proxmox Template Manage Role
|
||||
include_role:
|
||||
name: proxmox_template_manage
|
||||
|
||||
33
ansible/playbooks/hello_world_provision.yml
Normal file
33
ansible/playbooks/hello_world_provision.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
- name: Hello World Provisioning
|
||||
hosts: localhost # Run API calls from control node
|
||||
gather_facts: no
|
||||
vars_files:
|
||||
- "../inventory/hosts.ini" # Load connection details if needed manually, OR rely on inventory
|
||||
|
||||
vars:
|
||||
# Target Proxmox Details (override from inventory/extra vars)
|
||||
proxmox_api_host: "192.168.50.100"
|
||||
proxmox_api_user: "root@pam"
|
||||
proxmox_api_password: "Hemroid8" # Consider moving to Vault!
|
||||
proxmox_node: "mercury"
|
||||
|
||||
# VM Spec
|
||||
vmid: 101
|
||||
vm_name: "hello-world-vm"
|
||||
template_name: "ubuntu-2204-cloud"
|
||||
ci_user: "ubuntu"
|
||||
# Replace with your actual public key or pass via -e "ssh_key=..."
|
||||
ssh_keys:
|
||||
- "{{ ssh_key | default('ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...') }}"
|
||||
|
||||
tasks:
|
||||
- name: Run Proxmox Provision Role
|
||||
include_role:
|
||||
name: proxmox_provision
|
||||
vars:
|
||||
vmid: "{{ vmid }}"
|
||||
vm_name: "{{ vm_name }}"
|
||||
template_name: "{{ template_name }}"
|
||||
ci_user: "{{ ci_user }}"
|
||||
ssh_keys: "{{ ssh_keys }}"
|
||||
Reference in New Issue
Block a user