summaryrefslogtreecommitdiff
path: root/roles/vm/define/tasks/main.yml
blob: 4c2b99e12eb71cdae6c6a40c35d51d109e5958d9 (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
---
- name: check if vm already exists
  virt:
    name: "{{ hostname }}"
    command: info
  register: vmhost_info

- when: hostname in vmhost_info
  block:
    - name: destroy exisiting vm
      virt:
        name: "{{ hostname }}"
        state: destroyed

    - name: wait for vm to be destroyed
      wait_for_virt:
        name: "{{ hostname }}"
        states: shutdown,crashed
        timeout: 5

    - name: undefining exisiting vm
      virt:
        name: "{{ hostname }}"
        command: undefine

- name: define vm
  virt:
    command: define
    xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"

- when: vm_define_start | bool
  block:
    - name: start vm
      virt:
        name: "{{ hostname }}"
        state: running

    - name: wait for VM to start
      wait_for_virt:
        name: "{{ hostname }}"
        states: running
        timeout: 10

- name: mark vm as autostarted
  virt:
    name: "{{ hostname }}"
    autostart: "{{ vm_define_autostart }}"
    command: info ## virt module needs either command or state