2 - name: generate preseed file
4 src: "preseed_{{ vmdistro }}-{{ vmdistcodename }}.cfg.j2"
5 dest: "{{ hostvars[vm_install.host].vm_host.installer.preseed_path }}/vm-{{ inventory_hostname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg"
6 delegate_to: "{{ vm_install.host }}"
8 - name: create disks for vm
9 with_dict: "{{ vm_install.disks.virtio | default({}) | combine(vm_install.disks.scsi | default({})) }}"
11 vg: "{{ item.value.vg }}"
12 lv: "{{ item.value.lv }}"
13 size: "{{ item.value.size }}"
14 delegate_to: "{{ vm_install.host }}"
16 - name: check if vm already exists
18 name: "{{ inventory_hostname }}"
20 delegate_to: "{{ vm_install.host }}"
23 - name: destroy exisiting vm
25 name: "{{ inventory_hostname }}"
27 delegate_to: "{{ vm_install.host }}"
28 when: inventory_hostname in vmhost_info
30 - name: wait for vm to be destroyed
32 name: "{{ inventory_hostname }}"
33 states: shutdown,crashed
35 delegate_to: "{{ vm_install.host }}"
36 when: inventory_hostname in vmhost_info
38 - name: undefining exisiting vm
40 name: "{{ inventory_hostname }}"
42 delegate_to: "{{ vm_install.host }}"
43 when: inventory_hostname in vmhost_info
45 - name: enable installer in VM config
49 - name: define new installer vm
51 name: "{{ inventory_hostname }}"
53 xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
54 delegate_to: "{{ vm_install.host }}"
58 name: "{{ inventory_hostname }}"
60 delegate_to: "{{ vm_install.host }}"
62 - name: wait for installer to start
64 name: "{{ inventory_hostname }}"
67 delegate_to: "{{ vm_install.host }}"
70 msg: "you can check on the status of the installer running this command 'virsh console {{ inventory_hostname }}' on host {{ vm_install.host }}."
72 - name: wait for installer to finish or crash
74 name: "{{ inventory_hostname }}"
75 states: shutdown,crashed
77 delegate_to: "{{ vm_install.host }}"
78 register: installer_result
79 failed_when: installer_result.failed or installer_result.state == "crashed"
81 - name: undefining installer vm
83 name: "{{ inventory_hostname }}"
85 delegate_to: "{{ vm_install.host }}"
87 - name: disable installer in VM config
91 - name: define new production vm
93 name: "{{ inventory_hostname }}"
95 xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
96 delegate_to: "{{ vm_install.host }}"
100 name: "{{ inventory_hostname }}"
102 delegate_to: "{{ vm_install.host }}"
104 - name: mark vm as autostarted
106 name: "{{ inventory_hostname }}"
107 autostart: "{{ vm_install.autostart }}"
108 command: info ## virt module needs either command or state
109 delegate_to: "{{ vm_install.host }}"
110 when: vm_install.autostart is defined
112 ## TODO: find a better way to fetch host key of new VMs
113 - name: disable ssh StrictHostKeyChecking for the next step
115 ansible_ssh_extra_args: -o StrictHostKeyChecking=no
117 - name: wait for vm to start up
122 - name: reenable StrictHostKeyChecking
124 ansible_ssh_extra_args: ""