From 8530b93fea33f3df32a8b474b765c3860fd3c268 Mon Sep 17 00:00:00 2001 From: Maxim Vershinin Date: Sat, 19 Sep 2026 14:28:56 +0400 Subject: [PATCH] feat(pb,role,task): adds storage validation and uses it in LXC and VM deployment --- .../deploy_and_set_up_lxc_on_proxmox.yaml | 3 +++ playbooks/deploy_vm_from_cloud_init.yaml | 3 +++ roles/deploy_lxc_on_proxmox/tasks/main.yaml | 6 +++-- .../deploy_vm_on_proxmox/tasks/create_vm.yaml | 2 +- tasks/storage_validation.yaml | 22 +++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tasks/storage_validation.yaml diff --git a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml index 40d8c51..37aade9 100644 --- a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml +++ b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml @@ -26,6 +26,9 @@ - name: Include input and validation for human admin user creation ansible.builtin.include_tasks: ../tasks/human_admin_user_validation.yaml + - name: Include input and validation for storage selection + ansible.builtin.include_tasks: ../tasks/storage_validation.yaml + roles: - ../roles/deploy_lxc_on_proxmox diff --git a/playbooks/deploy_vm_from_cloud_init.yaml b/playbooks/deploy_vm_from_cloud_init.yaml index 9f28a50..13add7a 100644 --- a/playbooks/deploy_vm_from_cloud_init.yaml +++ b/playbooks/deploy_vm_from_cloud_init.yaml @@ -26,6 +26,9 @@ - name: Include input and validation for become method ansible.builtin.include_tasks: ../tasks/become_method_validation.yaml + - name: Include input and validation for storage selection + ansible.builtin.include_tasks: ../tasks/storage_validation.yaml + roles: - ../roles/deploy_vm_on_proxmox diff --git a/roles/deploy_lxc_on_proxmox/tasks/main.yaml b/roles/deploy_lxc_on_proxmox/tasks/main.yaml index d3e6261..9728ecf 100644 --- a/roles/deploy_lxc_on_proxmox/tasks/main.yaml +++ b/roles/deploy_lxc_on_proxmox/tasks/main.yaml @@ -22,8 +22,10 @@ # This is minimal requirement for rootfs # It might be resized later size: 4 # 4GB rootfs - # We put rootfs on fast local storage (NVMe SSD) - storage: local + # We put rootfs on user-selected sotrage + storage: "{{ guest_storage }}" + # We need timeout in case a slow storage is used, since it may cause a significant delay + timeout: 90 pubkey: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/ansible_key.pub') }}" netif: net0: "name=eth0,gw=192.168.0.1,ip={{ guest_ip_address }}/{{ guest_netmask }},bridge=vmbr0" diff --git a/roles/deploy_vm_on_proxmox/tasks/create_vm.yaml b/roles/deploy_vm_on_proxmox/tasks/create_vm.yaml index effc35c..5550f0d 100644 --- a/roles/deploy_vm_on_proxmox/tasks/create_vm.yaml +++ b/roles/deploy_vm_on_proxmox/tasks/create_vm.yaml @@ -12,7 +12,7 @@ clone: "{{ guest_os_template }}-cloud-init-template" name: "{{ guest_hostname }}" - storage: main + storage: "{{ guest_storage }}" format: qcow2 full: true timeout: 500 diff --git a/tasks/storage_validation.yaml b/tasks/storage_validation.yaml new file mode 100644 index 0000000..89203c2 --- /dev/null +++ b/tasks/storage_validation.yaml @@ -0,0 +1,22 @@ +--- + +- name: Set default storage + ansible.builtin.set_fact: + guest_storage: "main" + +- name: Prompt for guest storage with immediate validation + ansible.builtin.pause: + prompt: "Choose storage for root, available: main (HDD), local (PCIe NVMe SSD) [{{ guest_storage }}]" + register: storage_result + until: > + storage_result.user_input | length == 0 or + ( + storage_result.user_input in ['main', 'local'] + ) + retries: 2 + delay: 0 + +- name: Use user input only if provided, otherwise keep the default + ansible.builtin.set_fact: + guest_storage: "{{ storage_result.user_input }}" + when: storage_result.user_input | length > 0