feat: Manage container

This commit is contained in:
2026-04-24 01:50:56 +02:00
parent e3f6c9b02e
commit 785b45d349
4 changed files with 93 additions and 0 deletions

View File

@@ -74,6 +74,21 @@ proxmox_instance_cloudinit_nameservers: ""
proxmox_instance_cloudinit_searchdomains: null
proxmox_instance_cloudinit_sshkeys: ""
# Proxmox VE instance (CT)
proxmox_instance_disk_volumes: {}
# Example:
# storage: truenas-nfs
# size: 5G
proxmox_instance_features: []
proxmox_instance_mount_volumes: []
proxmox_instance_netif: {}
proxmox_instance_ostemplate: ""
proxmox_instance_ostype: auto
proxmox_instance_password: "{{ lookup('ansible.builtin.password', '/dev/null', seed=inventory_hostname, length=16) }}"
proxmox_instance_startup: ""
proxmox_instance_swap: 0
proxmox_instance_unprivileged: true
## HA configuration
proxmox_instance_ha:
max_restart: 3

View File

@@ -91,3 +91,15 @@
current: "{{ proxmox_current_instances.proxmox_vms | map(attribute='name') | sort }}"
expected: "{{ proxmox_node_instances.proxmox_vms | map(attribute='name') | sort }}"
listen: Disable maintenance mode
- name: Restart instance
community.proxmox.proxmox:
api_host: "{{ proxmox_api_host }}"
api_user: "{{ proxmox_api_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}"
vmid: "{{ proxmox_instance_vmid }}"
node: "{{ proxmox_instance_node }}"
state: restarted
when: not proxmox_instance_ct_started.changed
delegate_to: "{{ proxmox_delegate_to }}"

60
tasks/instance_ct.yml Normal file
View File

@@ -0,0 +1,60 @@
---
# tasks file for proxmox
- name: Deploy instance
community.proxmox.proxmox:
api_host: "{{ proxmox_api_host }}"
api_user: "{{ proxmox_api_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}"
cores: "{{ proxmox_instance_cores }}"
disk_volume: "{{ proxmox_instance_disk_volumes }}"
features: "{{ proxmox_instance_features }}"
hostname: "{{ inventory_hostname_short }}"
memory: "{{ proxmox_instance_memory }}"
mount_volumes: "{{ proxmox_instance_mount_volumes }}"
node: "{{ proxmox_instance_node }}"
onboot: "{{ proxmox_instance_onboot }}"
ostemplate: "{{ proxmox_instance_ostemplate }}"
ostype: "{{ proxmox_instance_ostype }}"
password: "{{ proxmox_instance_password }}"
startup: "{{ omit if proxmox_instance_startup | length == 0 else proxmox_instance_startup }}"
swap: "{{ proxmox_instance_swap }}"
timeout: 300
vmid: "{{ proxmox_instance_vmid }}"
netif: "{{ proxmox_instance_ipconfig }}"
delegate_to: "{{ proxmox_delegate_to }}"
notify: Restart instance
- name: Manage unprivileged option
ansible.builtin.lineinfile:
path: /etc/pve/lxc/{{ proxmox_instance_vmid }}.conf
regexp: '^unprivileged:'
line: "unprivileged: {{ proxmox_instance_unprivileged | int }}"
become: true
delegate_to: "{{ proxmox_delegate_to }}"
notify: Restart instance
- name: Manage protection option
ansible.builtin.lineinfile:
path: /etc/pve/lxc/{{ proxmox_instance_vmid }}.conf
regexp: '^protection:'
line: "protection: {{ proxmox_instance_protection | int }}"
become: true
delegate_to: "{{ proxmox_delegate_to }}"
notify: Restart instance
- name: Ensure instance is started
community.proxmox.proxmox:
api_host: "{{ proxmox_api_host }}"
api_user: "{{ proxmox_api_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}"
vmid: "{{ proxmox_instance_vmid }}"
node: "{{ proxmox_instance_node }}"
state: started
delegate_to: "{{ proxmox_delegate_to }}"
register: proxmox_instance_ct_started
- name: Flush handlers
ansible.builtin.meta: flush_handlers

View File

@@ -24,3 +24,9 @@
when:
- proxmox_instance_type == "vm"
- proxmox_instance_ha | length > 0
# Instance: ct
- name: Import instance creation tasks
ansible.builtin.include_tasks:
file: instance_ct.yml
when: proxmox_instance_type == "ct"