Make `run_installer` default to no in the libvirt template
[noc.git] / ansible / vm-update.yml
1 ---
2 - name: preperations and sanity checks
3   hosts: "{{ hostname }}"
4   gather_facts: no
5   tasks:
6   - name: setup variables
7     set_fact:
8       network_cooked: "{{ network }}"
9       install_cooked: "{{ install }}"
10
11   - name: create temporary host group for vm host
12     changed_when: no
13     add_host:
14       name: "{{ install_cooked.host }}"
15       inventory_dir: "{{inventory_dir}}"
16       group: _vmhost_
17   # TODO: add some sanity checks
18
19 - name: Update network configuration & shutdown VM
20   hosts: "{{ hostname }}"
21   gather_facts: no
22   roles:
23     - vm/network
24
25   tasks:
26     - meta: flush_handlers
27
28     - name: Shutdown VM
29       async: 1
30       poll: 0
31       ignore_errors: true
32       shell: sleep 2 && poweroff
33
34 - name: Update VM definition
35   hosts: _vmhost_
36   tasks:
37     - name: Wait for VM to shut down
38       wait_for_virt:
39         name: "{{ hostname }}"
40         states: shutdown
41         timeout: 30
42  
43     - name: Undefine VM
44       virt:
45         name: "{{ hostname }}"
46         command: undefine
47
48     - name: Redefine VM
49       virt:
50         name: "{{ hostname }}"
51         command: define
52         xml: "{{ lookup('template', 'roles/vm/install/templates/libvirt-domain.xml.j2') }}"
53
54     - name: Restart VM
55       virt:
56         name: "{{ hostname }}"
57         state: running
58
59     - name: mark vm as autostarted
60       when: hostvars[hostname].install_cooked.autostart is defined
61       virt:
62         name: "{{ hostname }}"
63         autostart: "{{ hostvars[hostname].install_cooked.autostart }}"
64         command: info ## virt module needs either command or state
65
66 - name: Apply the base vm/guest role
67   hosts: "{{ hostname }}"
68   pre_tasks:
69     - name: Wait for the VM to be up and running
70       wait_for_connection:
71         timeout: 120
72
73   roles:
74     - vm/guest