infra: introduce terraform/opentofu for proxmox management

- move ansible project within infra
- introduce terraform/opentofu for proxmox VM management
This commit is contained in:
2025-06-30 19:16:14 +03:00
parent a79de74a6a
commit 03c882f311
24 changed files with 882 additions and 0 deletions

View File

@ -0,0 +1,72 @@
- name: Get VM current state
delegate_to: localhost
vars:
ansible_python_interpreter: "{{ ansible_venv }}"
community.general.proxmox_kvm:
api_host: "{{ proxmox_api_url }}"
api_user: "{{ proxmox_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token }}"
name: "{{ item.name }}"
node: "{{ node }}"
state: current
register: vm_state
ignore_errors: yes
loop: "{{ vm_list }}"
loop_control:
index_var: vm_index
tags:
- vm_delete
- name: Debug VM state
debug:
msg: "VM {{ item.name }} state: {{ vm_state.results[vm_index].status }}"
when: vm_state.results[vm_index] is defined and vm_state.results[vm_index] is succeeded
loop: "{{ vm_list }}"
loop_control:
index_var: vm_index
- name: Stop VM
delegate_to: localhost
vars:
ansible_python_interpreter: "{{ ansible_venv }}"
community.general.proxmox_kvm:
api_host: "{{ proxmox_api_url }}"
api_user: "{{ proxmox_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token }}"
name: "{{ item.name }}"
node: "{{ node }}"
state: stopped
force: true
when: >
vm_state.results[vm_index] is defined and
vm_state.results[vm_index] is succeeded and
vm_state.results[vm_index].status != 'absent'
loop: "{{ vm_list }}"
loop_control:
index_var: vm_index
tags:
- vm_delete
- name: Delete VM
delegate_to: localhost
vars:
ansible_python_interpreter: "{{ ansible_venv }}"
community.general.proxmox_kvm:
api_host: "{{ proxmox_api_url }}"
api_user: "{{ proxmox_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token }}"
name: "{{ item.name }}"
node: "{{ node }}"
state: absent
when: >
vm_state.results[vm_index] is defined and
vm_state.results[vm_index] is succeeded and
vm_state.results[vm_index].status != 'absent'
loop: "{{ vm_list }}"
loop_control:
index_var: vm_index
tags:
- vm_delete