infra/home/ansible/create-postgres-lxc.yml
2025-09-06 10:55:13 -05:00

63 lines
No EOL
1.8 KiB
YAML

---
- name: Create PostgreSQL LXC Container on Proxmox
hosts: proxmox[0]
become: true
vars:
ct_id: 300
ct_name: postgres
ct_template: "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
ct_memory: 8192 # 8GB RAM
ct_disk_size: 1024 # 1TB storage
ct_cores: 4
ct_ip: "10.0.19.5/22"
ct_gateway: "10.0.19.254"
ct_storage: "ceph" # Use Ceph storage
tasks:
- name: Check if container already exists
command: pct status {{ ct_id }}
register: ct_exists
failed_when: false
changed_when: false
- name: Create PostgreSQL LXC container
command: |
pct create {{ ct_id }} {{ ct_template }} \
--hostname {{ ct_name }} \
--memory {{ ct_memory }} \
--cores {{ ct_cores }} \
--net0 name=eth0,bridge=vmbr0,ip={{ ct_ip }},gw={{ ct_gateway }} \
--storage {{ ct_storage }} \
--rootfs {{ ct_storage }}:{{ ct_disk_size }} \
--unprivileged 1 \
--features nesting=1 \
--onboot 1 \
--startup order=10
when: ct_exists.rc != 0
- name: Start container
command: pct start {{ ct_id }}
when: ct_exists.rc != 0
- name: Wait for container to be ready
wait_for:
host: 10.0.19.5
port: 22
timeout: 60
delay: 10
when: ct_exists.rc != 0
- name: Update container packages
shell: pct exec {{ ct_id }} -- apt update && pct exec {{ ct_id }} -- apt upgrade -y
when: ct_exists.rc != 0
- name: Display container info
debug:
msg: |
PostgreSQL LXC Container created:
- ID: {{ ct_id }}
- Name: {{ ct_name }}
- IP: 10.0.19.5
- RAM: {{ ct_memory }}MB
- Storage: {{ ct_disk_size }}GB
- Cores: {{ ct_cores }}