blob: d0790628316e52d6e0f4fa9d7cf957f2b2ebef97 (
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
|
---
- name: check if vm already exists
virt:
name: "{{ install_hostname }}"
command: info
register: vmhost_info
- name: remove old vm
when: install_hostname in vmhost_info
block:
- name: destroy exisiting vm
virt:
name: "{{ install_hostname }}"
state: destroyed
- name: wait for vm to be destroyed
wait_for_virt:
name: "{{ install_hostname }}"
states: shutdown,crashed
timeout: 5
- name: undefining exisiting vm
virt:
name: "{{ install_hostname }}"
command: undefine
- name: define vm
virt:
command: define
xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
- name: start new vm
when: vm_define_start | bool
block:
- name: start vm
virt:
name: "{{ install_hostname }}"
state: running
- name: wait for VM to start
wait_for_virt:
name: "{{ install_hostname }}"
states: running
timeout: 10
- name: mark vm as autostarted
virt:
name: "{{ install_hostname }}"
autostart: "{{ vm_define_autostart }}"
command: info ## virt module needs either command or state
|