diff options
author | Christian Pointner <equinox@spreadspace.org> | 2020-11-21 04:44:34 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2020-11-21 04:44:34 +0100 |
commit | 48d0df39753037b6688c55a372254ef9ecae5631 (patch) | |
tree | ed7c92eac51186d1284c2fe5005b7efa7d3411ae /roles/vm/guest | |
parent | use delegation for vm/guest install and define (diff) |
don't use install_hostname variable in roles
Diffstat (limited to 'roles/vm/guest')
-rw-r--r-- | roles/vm/guest/define/tasks/main.yml | 16 | ||||
-rw-r--r-- | roles/vm/guest/define/templates/libvirt-domain.xml.j2 | 8 | ||||
-rw-r--r-- | roles/vm/guest/install/tasks/main.yml | 10 |
3 files changed, 17 insertions, 17 deletions
diff --git a/roles/vm/guest/define/tasks/main.yml b/roles/vm/guest/define/tasks/main.yml index 65094bbb..a4405de1 100644 --- a/roles/vm/guest/define/tasks/main.yml +++ b/roles/vm/guest/define/tasks/main.yml @@ -2,28 +2,28 @@ - name: check if vm already exists delegate_to: "{{ vm_host_cooked.name }}" virt: - name: "{{ install_hostname }}" + name: "{{ inventory_hostname }}" command: info register: vmhost_info - name: remove old vm - when: install_hostname in vmhost_info + when: inventory_hostname in vmhost_info delegate_to: "{{ vm_host_cooked.name }}" block: - name: destroy exisiting vm virt: - name: "{{ install_hostname }}" + name: "{{ inventory_hostname }}" state: destroyed - name: wait for vm to be destroyed wait_for_virt: - name: "{{ install_hostname }}" + name: "{{ inventory_hostname }}" states: shutdown,crashed timeout: 5 - name: undefining exisiting vm virt: - name: "{{ install_hostname }}" + name: "{{ inventory_hostname }}" command: undefine - name: define vm @@ -38,18 +38,18 @@ block: - name: start vm virt: - name: "{{ install_hostname }}" + name: "{{ inventory_hostname }}" state: running - name: wait for VM to start wait_for_virt: - name: "{{ install_hostname }}" + name: "{{ inventory_hostname }}" states: running timeout: 10 - name: mark vm as autostarted delegate_to: "{{ vm_host_cooked.name }}" virt: - name: "{{ install_hostname }}" + name: "{{ inventory_hostname }}" autostart: "{{ vm_define_autostart }}" command: info ## virt module needs either command or state diff --git a/roles/vm/guest/define/templates/libvirt-domain.xml.j2 b/roles/vm/guest/define/templates/libvirt-domain.xml.j2 index ce8a48d4..28f237a9 100644 --- a/roles/vm/guest/define/templates/libvirt-domain.xml.j2 +++ b/roles/vm/guest/define/templates/libvirt-domain.xml.j2 @@ -1,5 +1,5 @@ <domain type='kvm'> - <name>{{ install_hostname }}</name> + <name>{{ inventory_hostname }}</name> <memory>{{ ((install_cooked.vm.memory | human_to_bytes) / 1024) | int }}</memory> <currentMemory>{{ ((install_cooked.vm.memory | human_to_bytes) / 1024) | int }}</currentMemory> <vcpu>{{ install_cooked.vm.numcpus }}</vcpu> @@ -44,7 +44,7 @@ {% if vm_define_installer and install_distro == 'openbsd' %} <disk type='file' device='cdrom'> <driver name='qemu'/> - <source file='{{ installer_tmpdir }}/{{ install_hostname }}.iso'/> + <source file='{{ installer_tmpdir }}/{{ inventory_hostname }}.iso'/> <target dev='hdc' bus='ide'/> <readonly/> </disk> @@ -57,7 +57,7 @@ {% if src.type == 'lvm' %} <source dev='/dev/mapper/{{ src.vg | replace('-', '--') }}-{{ src.lv | replace('-', '--') }}'/> {% elif src.type == 'zfs' %} - <source dev='/dev/zvol/{{ vm_host_cooked.zfs[src.backend | default('default')].pool }}/{{ vm_host_cooked.zfs[src.backend | default('default')].name }}/{{ install_hostname }}/{{ src.name }}'/> + <source dev='/dev/zvol/{{ vm_host_cooked.zfs[src.backend | default('default')].pool }}/{{ vm_host_cooked.zfs[src.backend | default('default')].name }}/{{ inventory_hostname }}/{{ src.name }}'/> {% endif %} <target dev='{{ device }}' bus='virtio'/> </disk> @@ -72,7 +72,7 @@ {% if src.type == 'lvm' %} <source dev='/dev/mapper/{{ src.vg | replace('-', '--') }}-{{ src.lv | replace('-', '--') }}'/> {% elif src.type == 'zfs' %} - <source dev='/dev/zvol/{{ vm_host_cooked.zfs[src.backend | default('default')].pool }}/{{ vm_host_cooked.zfs[src.backend | default('default')].name }}/{{ install_hostname }}/{{ src.name }}'/> + <source dev='/dev/zvol/{{ vm_host_cooked.zfs[src.backend | default('default')].pool }}/{{ vm_host_cooked.zfs[src.backend | default('default')].name }}/{{ inventory_hostname }}/{{ src.name }}'/> {% endif %} <target dev='{{ device }}' bus='scsi'/> </disk> diff --git a/roles/vm/guest/install/tasks/main.yml b/roles/vm/guest/install/tasks/main.yml index 0172c5bb..32bd9b7b 100644 --- a/roles/vm/guest/install/tasks/main.yml +++ b/roles/vm/guest/install/tasks/main.yml @@ -14,7 +14,7 @@ loop: "{{ install_cooked.disks.virtio | default({}) | combine(install_cooked.disks.scsi | default({})) | dict2items | selectattr('value.type', 'eq', 'zfs') | map(attribute='value.backend') | map('default', 'default') | unique | list }}" delegate_to: "{{ vm_host_cooked.name }}" zfs: - name: "{{ vm_host_cooked.zfs[item].pool }}/{{ vm_host_cooked.zfs[item].name }}/{{ install_hostname }}" + name: "{{ vm_host_cooked.zfs[item].pool }}/{{ vm_host_cooked.zfs[item].name }}/{{ inventory_hostname }}" state: present extra_zfs_properties: canmount: no @@ -26,7 +26,7 @@ label: "{{ item.value.name }} on backend {{ item.value.backend | default('default') }} ({{ item.value.size }})" delegate_to: "{{ vm_host_cooked.name }}" zfs: - name: "{{ vm_host_cooked.zfs[item.value.backend | default('default')].pool }}/{{ vm_host_cooked.zfs[item.value.backend | default('default')].name }}/{{ install_hostname }}/{{ item.value.name }}" + name: "{{ vm_host_cooked.zfs[item.value.backend | default('default')].pool }}/{{ vm_host_cooked.zfs[item.value.backend | default('default')].name }}/{{ inventory_hostname }}/{{ item.value.name }}" state: present extra_zfs_properties: "{{ item.value.properties | default({}) | combine({'volsize': item.value.size}) }}" @@ -36,7 +36,7 @@ - name: create a temporary workdir tempfile: path: "{{ hostvars[vm_host_cooked.name].installer_base_path }}/" - prefix: ".{{ install_hostname }}." + prefix: ".{{ inventory_hostname }}." state: directory register: tmpdir @@ -62,7 +62,7 @@ name: vm/guest/define - debug: - msg: "you can check on the status of the installer running this command 'virsh console {{ install_hostname }}' on host {{ vm_host_cooked.name }}." + msg: "you can check on the status of the installer running this command 'virsh console {{ inventory_hostname }}' on host {{ vm_host_cooked.name }}." - when: installer_manual_steps_msg is defined pause: @@ -75,7 +75,7 @@ - name: wait for installer to finish or crash wait_for_virt: - name: "{{ install_hostname }}" + name: "{{ inventory_hostname }}" states: shutdown,crashed timeout: 1800 register: installer_result |