-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-create.yml
79 lines (70 loc) · 2.34 KB
/
vm-create.yml
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
- hosts: all
become: true
gather_facts: false
tasks:
- name: Import zfs role for duplicate dataset check
ansible.builtin.include_role:
name: zfs
tasks_from: dataset-check-duplicate.yml
apply:
tags: zfs
delegate_to: "{{ hypervisor_host }}"
tags: zfs
- name: Import libvirt role for duplicate VM check
ansible.builtin.include_role:
name: libvirt
tasks_from: vm-check-duplicate.yml
apply:
tags: libvirt
delegate_to: "{{ hypervisor_host }}"
tags: libvirt
- name: Import zfs role for creating dataset
ansible.builtin.include_role:
name: zfs
tasks_from: dataset-create.yml
apply:
tags: zfs
delegate_to: "{{ hypervisor_host }}"
tags: zfs
- name: Block for VM creation and rescue for rolling back ZFS changes if creation fails
block:
- name: Import libvirt role for creating VM
ansible.builtin.include_role:
name: libvirt
tasks_from: vm-install.yml
apply:
tags: libvirt
delegate_to: "{{ hypervisor_host }}"
tags: libvirt
rescue:
- name: Print VM install failure message
ansible.builtin.debug:
msg: VM install failed, removing dataset
tags: always
- name: Import zfs role for checking dataset before destroy
ansible.builtin.include_role:
name: zfs
tasks_from: dataset-confirm-info.yml
apply:
tags: zfs
delegate_to: "{{ hypervisor_host }}"
tags: zfs
- name: Import zfs role for destroying dataset
ansible.builtin.include_role:
name: zfs
tasks_from: dataset-destroy.yml
apply:
tags: zfs
delegate_to: "{{ hypervisor_host }}"
tags: zfs
- name: Fail host
ansible.builtin.fail:
msg: Host failed build process
tags: always
- name: Import guest-configure role for configuring VM
ansible.builtin.include_role:
name: guest-configure
apply:
tags: guest-configure
tags: guest-configure
when: (ssh_key is defined and ssh_key | length > 0) or (root_password is defined and root_password | length > 0)