XMPP-service/playbooks/create_lxc.yml
2025-09-03 18:13:04 +02:00

47 lines
1.5 KiB
YAML

- name: Crea container lxc per prosody (xmpp)
hosts: proxmox_nodes
gather_facts: false
vars:
root_password: "{{ lookup('env', 'XMPP_PASSWORD') }}"
ssh_public_key: "{{ lookup('file', '~/.ssh/ansible.pub') }}"
vmid: 121
tasks:
- name: Create LXC
community.general.proxmox:
api_host: "{{ proxmox_url }}"
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
vmid: "{{ vmid }}"
node: milan
hostname: xmpp
ostemplate: "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
storage: slow1
cores: 1
memory: 512
netif:
net0: "name=eth0,bridge=vmbr1,ip=10.10.0.21/16,gw=10.10.0.1"
pubkey: "{{ ssh_public_key }}"
password: "{{ root_password }}"
features: "nesting=1"
state: present
delegate_to: localhost
register: lxc_creation_result #booooh, capiremo questo che vuol dire. Intanto registriamolo... immagino...
- name: Start LXC container
community.general.proxmox:
api_host: "{{ proxmox_url }}"
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
vmid: "{{ vmid }}"
node: milan
state: started # Tutto questo blocco è riassumibile in questa riga
delegate_to: localhost
when: lxc_creation_result.changed
- name: Aggiungi container all'inventory dinamico
add_host:
name: xmpp01
ansible_host: "10.10.0.21"
groups: lxc_containers
when: lxc_creation_result.changed