Refactor VM definition playbook and template to a separate role
[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   post_tasks:
26     - name: Shutdown VM
27       async: 1
28       poll: 0
29       ignore_errors: true
30       shell: sleep 2 && poweroff
31
32 - name: Update VM definition
33   hosts: _vmhost_
34   pre_tasks:
35     - name: Wait for VM to shut down
36       wait_for_virt:
37         name: "{{ hostname }}"
38         states: shutdown
39         timeout: 30
40
41   roles:
42     - vm/define
43
44 - name: Apply the base vm/guest role
45   hosts: "{{ hostname }}"
46   pre_tasks:
47     - name: Wait for the VM to be up and running
48       wait_for_connection:
49         timeout: 120
50
51   roles:
52     - vm/guest