From 8c3c3a9d4ed0c8cd51e48ef1c29af69370444493 Mon Sep 17 00:00:00 2001 From: harry Date: Fri, 10 Apr 2026 15:19:50 +0000 Subject: [PATCH] Add playbooks/new_lxc.yml --- playbooks/new_lxc.yml | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 playbooks/new_lxc.yml diff --git a/playbooks/new_lxc.yml b/playbooks/new_lxc.yml new file mode 100644 index 0000000..7a3ce56 --- /dev/null +++ b/playbooks/new_lxc.yml @@ -0,0 +1,75 @@ +--- +- name: Build Dynamic Rocky Linux LXC Container + hosts: localhost + gather_facts: false + + vars: + # --- Container Specifications --- + lxc_hostname: "new_lxc" + lxc_template: "local:vztmpl/rockylinux-9-default_20240912_amd64.tar.xz" + lxc_cores: 2 + lxc_memory: 1024 + lxc_storage: "TB" + lxc_disk_size: 10 + lxc_bridge: "vmbr0" + lxc_dns: "192.168.2.2" + target_node: "pve" + + # --- Security & Access --- + lxc_ssh_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINegitHaQG8i+s412h3wTWf/KvpeX1CEpYFva9MhHR+7 ansible-key" + + tasks: + - name: Get the next available VMID from the Proxmox cluster + ansible.builtin.uri: + url: "https://{{ proxmox_api_host }}:8006/api2/json/cluster/nextid" + method: GET + headers: + Authorization: "PVEAPIToken {{ proxmox_api_user }}={{ proxmox_api_password }}" + validate_certs: false + return_content: true + register: nextid_response + + - name: Extract the dynamic VMID from the API response + ansible.builtin.set_fact: + dynamic_vmid: "{{ nextid_response.json.data }}" + + - name: Create the Rocky Linux LXC container + community.general.proxmox: + api_host: "{{ proxmox_api_host }}" + api_user: "{{ proxmox_api_user }}" + api_password: "{{ proxmox_api_password }}" + + node: "{{ target_node }}" + vmid: "{{ dynamic_vmid }}" + hostname: "{{ lxc_hostname }}" + ostemplate: "{{ lxc_template }}" + cores: "{{ lxc_cores }}" + memory: "{{ lxc_memory }}" + + # FIX: Combined storage pool and size into the single required format + disk: "{{ lxc_storage }}:{{ lxc_disk_size }}" + + # Configure network for DHCP on the specified bridge + netif: '{"net0":"name=eth0,bridge={{ lxc_bridge }},ip=dhcp"}' + + # Explicitly set the DNS nameserver + nameserver: "{{ lxc_dns }}" + + # Inject the SSH public key + pubkey: "{{ lxc_ssh_key }}" + + # Highly recommended security flag for Proxmox containers + unprivileged: true + state: present + + - name: Ensure the new LXC container is powered on + community.general.proxmox: + api_host: "{{ proxmox_api_host }}" + api_user: "{{ proxmox_api_user }}" + api_password: "{{ proxmox_api_password }}" + vmid: "{{ dynamic_vmid }}" + state: started + + - name: Output the assigned VMID to the Semaphore UI logs + ansible.builtin.debug: + msg: "Successfully built {{ lxc_hostname }} (Rocky Linux 9) with dynamic ID: {{ dynamic_vmid }}" \ No newline at end of file