aboutsummaryrefslogtreecommitdiffstats
path: root/roles/vmm/tasks/disk.yml
blob: 58834029b2d2149f1b7818842ad2b9b4748a7a9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---

- name: create disks
  ansible.builtin.command:
    cmd: vmctl create -s "{{ item.size }}" "{{ item.name }}.{{ vmm_disk_format }}"
    chdir: "{{ vmm_disk_dir }}"
  loop: "{{ vmm_vms }}"
  register: result
  changed_when: result.rc == 0
  failed_when:
    - result.rc != 0
    - "'File exists' not in result.stderr"

- name: retrieve existing disks
  ansible.builtin.find:
    path: "{{ vmm_disk_dir }}"
    patterns: "*.{{ vmm_disk_format }}"
  register: result

- name: append disks informations to vms facts
  ansible.builtin.set_fact:
    vmm_vms_tmp: >
      {{ vmm_vms_tmp | default([]) + [ item | combine({
        "disk": result.files
          | selectattr("path", "regex", item.name, )
      }) ] }}
  loop: "{{ vmm_vms }}"

- name: save variables
  ansible.builtin.set_fact:
    vmm_vms: "{{ vmm_vms_tmp }}"
remember that computers suck.