X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=ansible%2Froles%2Fvm%2Finstall%2Ftasks%2Fmain.yml;h=35f2c8ecfd66a1e76abe384e2fcecd1bfb387268;hb=35ee18e05f6abc674fc2f6cbea2994e259d0624a;hp=39e625f5e14fe85a0d73b7af8ae7f55061fb0059;hpb=7aff1a3fbcaa717ef28bcc65111b374423a890a3;p=noc.git diff --git a/ansible/roles/vm/install/tasks/main.yml b/ansible/roles/vm/install/tasks/main.yml index 39e625f..35f2c8e 100644 --- a/ansible/roles/vm/install/tasks/main.yml +++ b/ansible/roles/vm/install/tasks/main.yml @@ -1,39 +1,6 @@ --- -- block: - - name: Make a temporary directory - command: mktemp -d - register: tmpdir - - - set_fact: - tmpdir: "{{ tmpdir.stdout }}" - initramfs: "{{ vm_host.installer.preseed_path }}/vm-{{ vmname }}-{{ vmdistro }}-{{ vmdistcodename }}.initrd.gz" - - - name: Copy initramfs into position - copy: - remote_src: yes - src: "{{ vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ hostvars[vmname].vm_install_cooked.arch | default('amd64') }}/initrd.gz" - dest: "{{ initramfs }}" - - - name: generate preseed file - template: - src: "preseed_{{ vmdistro }}-{{ vmdistcodename }}.cfg.j2" - dest: "{{ tmpdir }}/preseed.cfg" - - - name: Inject files into initramfs - shell: cpio -H newc -o | gzip -9 >> {{ initramfs }} - args: - chdir: "{{ tmpdir }}" - stdin: | - preseed.cfg - - always: - - name: Delete temporary directory - file: - path: "{{ tmpdir }}" - state: absent - - 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].install_cooked.disks.virtio | default({}) | combine(hostvars[hostname].install_cooked.disks.scsi | default({})) }}" lvol: vg: "{{ item.value.vg }}" lv: "{{ item.value.lv }}" @@ -41,84 +8,80 @@ - 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 - -- name: enable installer in VM config - set_fact: - run_installer: True + when: hostname in vmhost_info - name: define new installer vm virt: - name: "{{ vmname }}" + name: "{{ hostname }}" command: define xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}" + vars: + run_installer: yes - 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: 900 + timeout: 1800 register: installer_result failed_when: installer_result.failed or installer_result.state == "crashed" - name: undefining installer vm virt: - name: "{{ vmname }}" + name: "{{ hostname }}" command: undefine -- name: disable installer in VM config - set_fact: - run_installer: False - - name: define new production vm virt: - name: "{{ vmname }}" + name: "{{ hostname }}" command: define xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}" + vars: + run_installer: no - 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].install_cooked.autostart }}" command: info ## virt module needs either command or state - when: hostvars[vmname].vm_install_cooked.autostart is defined + when: hostvars[hostname].install_cooked.autostart is defined