diff options
Diffstat (limited to 'ansible/deployment_poc/tasks/configure_libvirt.yml')
-rw-r--r-- | ansible/deployment_poc/tasks/configure_libvirt.yml | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/ansible/deployment_poc/tasks/configure_libvirt.yml b/ansible/deployment_poc/tasks/configure_libvirt.yml index b3e49b6..3b20529 100644 --- a/ansible/deployment_poc/tasks/configure_libvirt.yml +++ b/ansible/deployment_poc/tasks/configure_libvirt.yml @@ -1,28 +1,6 @@ --- - name: Provision VM block: - - name: Create domain template - ansible.builtin.template: - src: "../templates/libvirt-template.xml.j2" - dest: "../templates/libvirt-{{ inventory_hostname }}.xml" - group: lysergic - mode: '0660' - - - name: Create storage template - ansible.builtin.template: - src: "../templates/libvirt-storage-template.xml.j2" - dest: "../templates/generated/libvirt-storage-{{ inventory_hostname }}.xml" - group: lysergic - mode: '0660' - - - name: Define domain - virt: - uri: "{{ libvirt_url }}" - command: define - xml: "{{ lookup('template', '../templates/libvirt-template.xml.j2') }}" - autostart: no - # delegate_to: localhost - - name: Query volumes ansible.builtin.command: argv: @@ -34,6 +12,14 @@ register: volumes no_log: true + - name: Create storage template + ansible.builtin.template: + src: "../templates/libvirt-storage-template.xml.j2" + dest: "../templates/generated/libvirt-storage-{{ inventory_hostname }}.xml" + group: lysergic + mode: '0660' + when: vm_name not in volumes.stdout + - name: Define volume ansible.builtin.command: argv: @@ -45,8 +31,40 @@ - "../templates/generated/libvirt-storage-{{ inventory_hostname }}.xml" when: vm_name not in volumes.stdout + # https://gitlab.com/libvirt/libvirt/-/issues/135 + - name: Fetch volume path + ansible.builtin.command: + argv: + - /usr/bin/virsh + - -c + - "{{ libvirt_url }}" + - vol-path + - --pool + - "{{ storage.name }}" + - "{{ inventory_hostname }}_root_disk.qcow2" + register: volpath + + - name: Store volume path + set_fact: + volume_path: "{{ volpath.stdout }}" + + - name: Create domain template + ansible.builtin.template: + src: "../templates/libvirt-template.xml.j2" + dest: "../templates/libvirt-{{ inventory_hostname }}.xml" + group: lysergic + mode: '0660' + + - name: Define domain + community.libvirt.virt: + uri: "{{ libvirt_url }}" + command: define + xml: "{{ lookup('template', '../templates/libvirt-template.xml.j2') }}" + autostart: no + # delegate_to: localhost + - name: Fetch MAC address - ansible.builtin.shell: "/usr/bin/virsh -c {{ libvirt_url }} domiflist {{ vm_name }} | awk '{print $5}' | cut -d/ -f 1 | tail -n 2 | head -n1" # ewww :-( + ansible.builtin.shell: "/usr/bin/virsh -c {{ libvirt_url }} domiflist {{ vm_name }} | awk '{print $5}' | cut -d/ -f 1 | tail -n 2 | head -n 1" # ewww :-( register: domiflist_mac - name: Store MAC address |