---
- name: create disks for vm
- with_dict: "{{ hostvars[vmname].vm_install_cooked.disks.virtio | default({}) | combine(hostvars[vmname].vm_install_cooked.disks.scsi | default({})) }}"
+ with_dict: "{{ hostvars[hostname].vm_install_cooked.disks.virtio | default({}) | combine(hostvars[hostname].vm_install_cooked.disks.scsi | default({})) }}"
lvol:
vg: "{{ item.value.vg }}"
lv: "{{ item.value.lv }}"
- name: check if vm already exists
virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
command: info
register: vmhost_info
- block:
- name: destroy exisiting vm
virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
state: destroyed
- name: wait for vm to be destroyed
wait_for_virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
states: shutdown,crashed
timeout: 5
- name: undefining exisiting vm
virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
command: undefine
- when: vmname in vmhost_info
+ when: hostname in vmhost_info
- name: enable installer in VM config
set_fact:
- name: define new installer vm
virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
command: define
xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
- name: start vm
virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
state: running
- name: wait for installer to start
wait_for_virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
states: running
timeout: 10
- debug:
- msg: "you can check on the status of the installer running this command 'virsh console {{ vmname }}' on host {{ inventory_hostname }}."
+ msg: "you can check on the status of the installer running this command 'virsh console {{ hostname }}' on host {{ inventory_hostname }}."
- name: wait for installer to finish or crash
wait_for_virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
states: shutdown,crashed
timeout: 1800
register: installer_result
- name: undefining installer vm
virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
command: undefine
- name: disable installer in VM config
- name: define new production vm
virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
command: define
xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
- name: start vm
virt:
- name: "{{ vmname }}"
+ name: "{{ hostname }}"
state: running
- name: mark vm as autostarted
virt:
- name: "{{ vmname }}"
- autostart: "{{ hostvars[vmname].vm_install_cooked.autostart }}"
+ name: "{{ hostname }}"
+ autostart: "{{ hostvars[hostname].vm_install_cooked.autostart }}"
command: info ## virt module needs either command or state
- when: hostvars[vmname].vm_install_cooked.autostart is defined
+ when: hostvars[hostname].vm_install_cooked.autostart is defined