|
8 | 8 | path: "{{ install_iso_windows }}"
|
9 | 9 | get_checksum: false
|
10 | 10 | register: install_iso_windows_stat
|
| 11 | + |
11 | 12 | - name: Complain about missing Windows ISO
|
12 | 13 | ansible.builtin.fail:
|
13 | 14 | msg: "Windows ISO could not be found, please download it from https://www.microsoft.com/en-us/evalcenter/download-windows-server-2022 and put it at {{ install_iso_windows }} (or modify install_iso_windows to point at the correct path)"
|
|
18 | 19 | dest: "{{ install_iso_virtio_win }}"
|
19 | 20 | url: "{{ install_iso_virtio_win_url }}"
|
20 | 21 | checksum: "{{ install_iso_virtio_win_checksum }}"
|
| 22 | + |
21 | 23 | - name: Download SPICE guest tools
|
22 | 24 | ansible.builtin.get_url:
|
23 | 25 | dest: "{{ install_exe_spice_guest_tools }}"
|
|
30 | 32 | command: define
|
31 | 33 | xml: "{{ lookup('template', 'windows-vm-network.xml.j2') }}"
|
32 | 34 | uri: "{{ libvirt_uri }}"
|
| 35 | + |
33 | 36 | - name: Start VM Network
|
34 | 37 | community.libvirt.virt_net:
|
35 | 38 | name: "{{ vm_network_hostnet_name }}"
|
36 | 39 | state: active
|
37 | 40 | uri: "{{ libvirt_uri }}"
|
| 41 | + |
| 42 | +- name: Create VM Network (Internet) |
| 43 | + community.libvirt.virt_net: |
| 44 | + name: "{{ vm_network_internet_name }}" |
| 45 | + command: define |
| 46 | + xml: "{{ lookup('template', 'windows-vm-network-internet.xml.j2') }}" |
| 47 | + uri: "{{ libvirt_uri }}" |
| 48 | + |
| 49 | +- name: Start VM Network (Internet) |
| 50 | + community.libvirt.virt_net: |
| 51 | + name: "{{ vm_network_internet_name }}" |
| 52 | + state: active |
| 53 | + uri: "{{ libvirt_uri }}" |
| 54 | + |
38 | 55 | - name: Create VM
|
39 | 56 | community.libvirt.virt:
|
40 | 57 | command: define
|
|
43 | 60 | - ADD_UUID
|
44 | 61 | - ADD_MAC_ADDRESSES
|
45 | 62 | uri: "{{ libvirt_uri }}"
|
| 63 | + |
46 | 64 | - name: Check if VM Volume already exists
|
47 | 65 | # Ansible has no idempotent way to define libvirt volumes,
|
48 | 66 | # so instead try to check whether it exists.
|
|
52 | 70 | # Errors should cause the create step to fail anyway
|
53 | 71 | failed_when: False
|
54 | 72 | changed_when: result_check_vm_disk.rc != 0
|
| 73 | + |
55 | 74 | - name: Create VM Volume
|
56 | 75 | when: result_check_vm_disk is changed
|
57 | 76 | ansible.builtin.command:
|
58 | 77 | cmd: virsh --connect "{{ libvirt_uri }}" vol-create --pool "{{ vm_disk_pool }}" --file /dev/stdin
|
59 | 78 | stdin: "{{ lookup('template', 'windows-vm-volume.xml.j2') }}"
|
| 79 | + |
60 | 80 | - name: Start VM
|
61 | 81 | community.libvirt.virt:
|
62 | 82 | name: "{{ vm_name }}"
|
63 | 83 | state: running
|
64 | 84 | uri: "{{ libvirt_uri }}"
|
| 85 | + |
65 | 86 | - name: Get VM Metadata
|
66 | 87 | community.libvirt.virt:
|
67 | 88 | name: "{{ vm_name }}"
|
68 | 89 | command: get_xml
|
69 | 90 | uri: "{{ libvirt_uri }}"
|
70 | 91 | register: created_vm
|
| 92 | + |
71 | 93 | # VM can have multiple NICs, extract the one we care about so we can match it against the IP address of the guest later
|
72 | 94 | - name: Extract VM's MAC address
|
73 | 95 | community.general.xml:
|
74 | 96 | xmlstring: "{{ created_vm.get_xml }}"
|
75 | 97 | xpath: /domain/devices/interface[alias/@name="ua-net-hostnet"]/mac
|
76 | 98 | content: attribute
|
77 | 99 | register: vm_network_mac_xml
|
| 100 | + |
78 | 101 | - set_fact:
|
79 | 102 | vm_network_mac: "{{ vm_network_mac_xml.matches[0].mac.address }}"
|
80 | 103 | delegate_to: sble-addc
|
|
0 commit comments