vm-install: Remove hosts from known hosts in the playbook
[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 - import_playbook: remove_known_hosts.yml
18
19 - name: basic installation
20   hosts: _vmhost_
21   roles:
22   - role: vm/install
23
24 - name: wait for new vm to start up
25   hosts: "{{ vmname }}"
26   gather_facts: no
27   tasks:
28     ## TODO: find a better way to fetch host key of new VMs
29   - name: disable ssh StrictHostKeyChecking for the next step
30     set_fact:
31       ansible_ssh_extra_args: -o StrictHostKeyChecking=no
32   - name: wait for vm to start up
33     wait_for_connection:
34       delay: 5
35       timeout: 120
36   - name: reenable StrictHostKeyChecking
37     set_fact:
38       ansible_ssh_extra_args: ""
39
40 - name: Apply VM configuration roles
41   hosts: "{{ vmname }}"
42   roles:
43   - role: vm/grub
44   - role: vm/network
45   - role: vm/guest
46
47 - import_playbook: "host_playbooks/{{ vmname }}.yml"
48
49 - name: reboot and wait for VM come back
50   hosts: "{{ vmname }}"
51   gather_facts: no
52   roles:
53   - role: reboot-and-wait
54     reboot_delay: 10
55     reboot_timeout: 120