summaryrefslogtreecommitdiff
path: root/roles/vm/guest/install/tasks/main.yml
blob: f2bd53627566b4b1d9197495357f5308d1045822 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
- name: create lvm-based disks for vm
  loop: "{{ install.disks.virtio | default({}) | combine(install.disks.scsi | default({})) | dict2items | selectattr('value.type', 'eq', 'lvm') | list }}"
  loop_control:
    label: "{{ item.value.vg }} / {{ item.value.lv }}  ({{ item.value.size }})"
  delegate_to: "{{ vm_host.name }}"
  lvol:
    vg: "{{ item.value.vg }}"
    lv: "{{ item.value.lv }}"
    size: "{{ item.value.size }}"
    state: present

- name: create zfs base datasets for vm
  loop: "{{ install.disks.virtio | default({}) | combine(install.disks.scsi | default({})) | dict2items | selectattr('value.type', 'eq', 'zfs') | map(attribute='value.backend') | map('default', 'default') | unique | list }}"
  delegate_to: "{{ vm_host.name }}"
  zfs:
    name: "{{ vm_host.zfs[item].pool }}/{{ vm_host.zfs[item].name }}/{{ inventory_hostname }}"
    state: present
    extra_zfs_properties:
      canmount: no
      mountpoint: none

- name: create zfs-based disk volumes for vm
  loop: "{{ install.disks.virtio | default({}) | combine(install.disks.scsi | default({})) | dict2items | selectattr('value.type', 'eq', 'zfs') | list }}"
  loop_control:
    label: "{{ item.value.name }} on backend {{ item.value.backend | default('default') }} ({{ item.value.size }})"
  delegate_to: "{{ vm_host.name }}"
  zfs:
    name: "{{ vm_host.zfs[item.value.backend | default('default')].pool }}/{{ vm_host.zfs[item.value.backend | default('default')].name }}/{{ inventory_hostname }}/{{ item.value.name }}"
    state: present
    extra_zfs_properties: "{{ item.value.properties | default({}) | combine({'volsize': item.value.size}) | dehumanize_zfs_properties }}"


- delegate_to: "{{ vm_host.name }}"
  block:
  - name: create a temporary workdir
    tempfile:
      path: "{{ hostvars[vm_host.name].installer_base_path }}/"
      prefix: ".{{ inventory_hostname }}."
      state: directory
    register: tmpdir

  - when: install_distro in ['debian', 'ubuntu']
    import_tasks: installer-debian.yml

  - when: install_distro in ['openbsd']
    import_tasks: installer-openbsd.yml

  - name: Make installer workdir readable by qemu
    acl:
      path: "{{ tmpdir.path }}"
      state: present
      entity: libvirt-qemu
      etype: user
      permissions: rx

  - name: define installer vm
    vars:
      vm_define_installer: yes
      installer_tmpdir: "{{ tmpdir.path }}"
    import_role:
      name: vm/guest/define

  - debug:
      msg: "you can check on the status of the installer running this command 'virsh console {{ inventory_hostname }}' on host {{ vm_host.name }}."

  - when: installer_manual_steps_msg is defined
    pause:
      prompt: |
        Mind that this installer needs manual steps to be performed:

          {{ installer_manual_steps_msg | indent(2) }}

        When done press ENTER to continue or CTRL-C then A to abort.

  - name: wait for installer to finish or crash
    wait_for_virt:
      name: "{{ inventory_hostname }}"
      states: shutdown,crashed
      timeout: 1800
    register: installer_result
    failed_when: installer_result.failed or installer_result.state == "crashed"

  always:
  - name: cleanup temporary workdir
    file:
      path: "{{ tmpdir.path }}"
      state: absent

- name: define vm
  vars:
    vm_define_installer: no
  delegate_to: "{{ vm_host.name }}"
  import_role:
    name: vm/guest/define