vm-install: Apply VM configuration roles
[noc.git] / ansible / vm-install.yml
1 ---
2 - name: preperations and sanity checks
3   hosts: "{{ vmname }}"
4   gather_facts: no
5   tasks:
6   - name: setup variables
7     set_fact:
8       vm_network_cooked: "{{ vm_network }}"
9       vm_install_cooked: "{{ vm_install }}"
10   - name: create temporary host group for vm host
11     add_host:
12       name: "{{ vm_install.host }}"
13       inventory_dir: "{{inventory_dir}}"
14       group: _vmhost_
15   # TODO: add some sanity checks
16
17 - name: basic installation
18   hosts: _vmhost_
19   roles:
20   - role: vm/install
21
22 - name: wait for new vm to start up
23   hosts: "{{ vmname }}"
24   gather_facts: no
25   tasks:
26     ## TODO: find a better way to fetch host key of new VMs
27   - name: disable ssh StrictHostKeyChecking for the next step
28     set_fact:
29       ansible_ssh_extra_args: -o StrictHostKeyChecking=no
30   - name: wait for vm to start up
31     wait_for_connection:
32       delay: 5
33       timeout: 120
34   - name: reenable StrictHostKeyChecking
35     set_fact:
36       ansible_ssh_extra_args: ""
37
38 - name: Apply VM configuration roles
39   hosts: "{{ vmname }}"
40   roles:
41   - role: vm/grub
42   - role: vm/network
43   - role: vm/guest
44
45 - import_playbook: "host_playbooks/{{ vmname }}.yml"
46
47 - name: reboot and wait for VM come back
48   hosts: "{{ vmname }}"
49   gather_facts: no
50   roles:
51   - role: reboot-and-wait
52     reboot_delay: 10
53     reboot_timeout: 120