diff --git a/roles/proxmox_lxc/tasks/main.yml b/roles/proxmox_lxc/tasks/main.yml index 94d6282..49b4d03 100644 --- a/roles/proxmox_lxc/tasks/main.yml +++ b/roles/proxmox_lxc/tasks/main.yml @@ -1,20 +1,32 @@ --- -- name: Create Gateway LXC container - community.proxmox.proxmox_lxc: - node: "{{ proxmox_node }}" - vmid: 221 - hostname: gateway - storage: "vmsystem" - cores: 1 - memory: 2048 - swap: 512 - rootfs: "vmsystem:5" - template: "ubuntu-24.04-standard_24.04-2_amd64.tar.zst" - password: "{{ proxmox_root_password }}" - net: - name: eth0 - bridge: vmbr0 - ip: 192.168.1.221/24 - gw: 192.168.1.1 - unprivileged: true - state: present \ No newline at end of file +- name: Check if container already exists + shell: pct list | grep 221 || true + register: container_check + delegate_to: "{{ groups['proxmox_servers'][0] }}" + changed_when: false + +- name: Create Gateway LXC container using pct command + shell: | + pct create 221 \ + /var/lib/vz/template/cache/ubuntu-24.04-standard_24.04-2_amd64.tar.zst \ + --rootfs vmsystem:5 \ + --cores 1 \ + --memory 2048 \ + --swap 512 \ + --hostname gateway \ + --net0 name=eth0,bridge=vmbr0,ip=192.168.1.221/24,gw=192.168.1.1 \ + --storage vmsystem \ + --password {{ proxmox_root_password }} \ + --unprivileged 1 \ + --start 1 + args: + executable: /bin/bash + delegate_to: "{{ groups['proxmox_servers'][0] }}" + when: "'221' not in container_check.stdout" + +- name: Wait for container to start + wait_for_connection: + host: 192.168.1.221 + port: 22 + timeout: 60 + delay: 5 \ No newline at end of file