From a35d8ae32c15cbd8b837ad94cabecf05d3331281 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sat, 8 Jun 2024 01:22:08 +0100 Subject: [PATCH] Backups VM --- infra/backups/0000_proxmox_playbook.yaml | 88 ++++++++++++++++++++++++ inventory/proxmox.yaml | 5 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 infra/backups/0000_proxmox_playbook.yaml diff --git a/infra/backups/0000_proxmox_playbook.yaml b/infra/backups/0000_proxmox_playbook.yaml new file mode 100644 index 0000000..8c5e01a --- /dev/null +++ b/infra/backups/0000_proxmox_playbook.yaml @@ -0,0 +1,88 @@ +- name: Provision backups Proxmox VM + hosts: backups + connection: ansible.builtin.local + gather_facts: false + vars: + api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}" + api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}" + api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') }}" + api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}" + ssh_public: "{{ lookup('ansible.builtin.env', 'SSH_PUBLIC') }}" + vmname: "{{ inventory_hostname | regex_replace('^([^\\.]+)\\..+$', '\\1') }}" + node: pve + module_defaults: + community.general.proxmox_kvm: + api_user: "{{ api_user }}" + api_host: "{{ api_host }}" + api_token_id: "{{ api_token_id }}" + api_token_secret: "{{ api_token_secret }}" + name: "{{ vmname }}" + node: "{{ node }}" + community.general.proxmox_nic: + api_user: "{{ api_user }}" + api_host: "{{ api_host }}" + api_token_id: "{{ api_token_id }}" + api_token_secret: "{{ api_token_secret }}" + name: "{{ vmname }}" + community.general.proxmox_disk: + api_user: "{{ api_user }}" + api_host: "{{ api_host }}" + api_token_id: "{{ api_token_id }}" + api_token_secret: "{{ api_token_secret }}" + name: "{{ vmname }}" + tasks: + # Initial setup + - name: Create VM + community.general.proxmox_kvm: + clone: "{{ node }}-base" + storage: nvme + notify: Initial boot + - name: Wait for status + community.general.proxmox_kvm: + state: current + register: vm + retries: 30 + delay: 10 + until: vm.status is defined + + # Networking and initial config + - name: Add PUB NIC + community.general.proxmox_nic: + interface: net0 + firewall: false + bridge: PUB + - name: Add SRV NIC + community.general.proxmox_nic: + interface: net1 + firewall: false + bridge: SRV + + # VM Configuration + - name: Create CD disk + community.general.proxmox_disk: + disk: ide2 + media: cdrom + iso_image: none + - name: Create root disk + community.general.proxmox_disk: + disk: scsi0 + backup: true + storage: nvme + size: 32 + - name: Create data disk + community.general.proxmox_disk: + disk: scsi1 + backup: false + storage: zfs + size: 2048 + - name: Update VM + community.general.proxmox_kvm: + update: true + boot: order=scsi0;ide2 + agent: enabled=1 + tags: + - debian-12 + - managed + onboot: true + cores: 4 + memory: 4096 diff --git a/inventory/proxmox.yaml b/inventory/proxmox.yaml index e38e2c4..eba18c0 100644 --- a/inventory/proxmox.yaml +++ b/inventory/proxmox.yaml @@ -31,4 +31,7 @@ proxmox: ansible_ssh_private_key_file: ~/.ssh/id_rsa ansible_ssh_common_args: -o StrictHostKeyChecking=accept-new # TODO: Improve this unmanaged: - hosts: + children: + backups: + hosts: + backups.srv.home.local.koval.net: