libvirt role
This commit is contained in:
parent
63116af524
commit
21679647c6
13
ansible/roles/libvirt-server/defaults/main.yml
Normal file
13
ansible/roles/libvirt-server/defaults/main.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
libvirt_server_packages:
|
||||||
|
- qemu-base
|
||||||
|
- libvirt
|
||||||
|
- bridge-utils
|
||||||
|
- openbsd-netcat
|
||||||
|
- edk2-ovmf
|
||||||
|
- swtpm
|
||||||
|
|
||||||
|
libvirt_zfs_pool_name: zfs
|
||||||
|
libvirt_iso_pool_name: iso
|
||||||
|
libvirt_qcow_pool_name: qcow
|
||||||
|
libvirt_vm_network_name: br22
|
92
ansible/roles/libvirt-server/tasks/main.yml
Normal file
92
ansible/roles/libvirt-server/tasks/main.yml
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
---
|
||||||
|
- name: install libvirt server packages
|
||||||
|
become: true
|
||||||
|
community.general.pacman:
|
||||||
|
name: "{{ libvirt_server_packages }}"
|
||||||
|
state: latest
|
||||||
|
update_cache: true
|
||||||
|
reason: explicit
|
||||||
|
when:
|
||||||
|
- ansible_os_family == 'Arch'
|
||||||
|
|
||||||
|
- name: add user to libvirt group
|
||||||
|
become: true
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: "{{ ansible_user }}"
|
||||||
|
groups: libvirt
|
||||||
|
append: true
|
||||||
|
|
||||||
|
- name: start and enable libvirt service
|
||||||
|
become: true
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: libvirtd.service
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
|
||||||
|
- name: define vm network
|
||||||
|
community.libvirt.virt_net:
|
||||||
|
name: "{{ libvirt_vm_network_name }}"
|
||||||
|
command: define
|
||||||
|
xml: '{{ lookup("template", "network.xml.j2") }}'
|
||||||
|
|
||||||
|
- name: build vm network
|
||||||
|
community.libvirt.virt_net:
|
||||||
|
name: "{{ libvirt_vm_network_name }}"
|
||||||
|
command: build
|
||||||
|
|
||||||
|
- name: start vm network
|
||||||
|
community.libvirt.virt_net:
|
||||||
|
name: "{{ libvirt_vm_network_name }}"
|
||||||
|
state: active
|
||||||
|
autostart: true
|
||||||
|
|
||||||
|
- name: define zfs storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_zfs_pool_name }}"
|
||||||
|
command: define
|
||||||
|
xml: '{{ lookup("template", "zfs.xml.j2") }}'
|
||||||
|
|
||||||
|
- name: build zfs storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_zfs_pool_name }}"
|
||||||
|
command: build
|
||||||
|
|
||||||
|
- name: start zfs storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_zfs_pool_name }}"
|
||||||
|
state: active
|
||||||
|
autostart: true
|
||||||
|
|
||||||
|
- name: define iso storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_iso_pool_name }}"
|
||||||
|
command: define
|
||||||
|
xml: '{{ lookup("template", "iso.xml.j2") }}'
|
||||||
|
|
||||||
|
- name: build iso storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_iso_pool_name }}"
|
||||||
|
command: build
|
||||||
|
|
||||||
|
- name: start iso storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_iso_pool_name }}"
|
||||||
|
state: active
|
||||||
|
autostart: true
|
||||||
|
|
||||||
|
- name: define qcow storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_qcow_pool_name }}"
|
||||||
|
command: define
|
||||||
|
xml: '{{ lookup("template", "qcow.xml.j2") }}'
|
||||||
|
|
||||||
|
- name: build qcow storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_qcow_pool_name }}"
|
||||||
|
command: build
|
||||||
|
|
||||||
|
- name: start qcow storage pool
|
||||||
|
community.libvirt.virt_pool:
|
||||||
|
name: "{{ libvirt_qcow_pool_name }}"
|
||||||
|
state: active
|
||||||
|
autostart: true
|
17
ansible/roles/libvirt-server/templates/iso.xml.j2
Normal file
17
ansible/roles/libvirt-server/templates/iso.xml.j2
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<pool type="dir">
|
||||||
|
<name>iso</name>
|
||||||
|
<uuid>c7be6440-728c-4181-b7e8-68bf3094740a</uuid>
|
||||||
|
<capacity unit="bytes">208525328384</capacity>
|
||||||
|
<allocation unit="bytes">31027101696</allocation>
|
||||||
|
<available unit="bytes">177498226688</available>
|
||||||
|
<source>
|
||||||
|
</source>
|
||||||
|
<target>
|
||||||
|
<path>/mnt/smb/isos</path>
|
||||||
|
<permissions>
|
||||||
|
<mode>0755</mode>
|
||||||
|
<owner>1000</owner>
|
||||||
|
<group>1000</group>
|
||||||
|
</permissions>
|
||||||
|
</target>
|
||||||
|
</pool>
|
12
ansible/roles/libvirt-server/templates/network.xml.j2
Normal file
12
ansible/roles/libvirt-server/templates/network.xml.j2
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<network>
|
||||||
|
<name>default</name>
|
||||||
|
<uuid>ea5ab2e3-1c95-49de-af3b-131a836f4b7b</uuid>
|
||||||
|
<forward mode="nat"/>
|
||||||
|
<bridge name="virbr0" stp="on" delay="0"/>
|
||||||
|
<mac address="52:54:00:63:57:8d"/>
|
||||||
|
<ip address="192.168.122.1" netmask="255.255.255.0">
|
||||||
|
<dhcp>
|
||||||
|
<range start="192.168.122.2" end="192.168.122.254"/>
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
0
ansible/roles/libvirt-server/templates/qcow.xml.j2
Normal file
0
ansible/roles/libvirt-server/templates/qcow.xml.j2
Normal file
13
ansible/roles/libvirt-server/templates/zfs.xml.j2
Normal file
13
ansible/roles/libvirt-server/templates/zfs.xml.j2
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<pool type="zfs">
|
||||||
|
<name>zfs-nvme</name>
|
||||||
|
<uuid>026cccc9-ee79-467a-bf19-91e6f3d2531d</uuid>
|
||||||
|
<capacity unit="bytes">498216206336</capacity>
|
||||||
|
<allocation unit="bytes">185811460096</allocation>
|
||||||
|
<available unit="bytes">312404746240</available>
|
||||||
|
<source>
|
||||||
|
<name>nvme/vhds</name>
|
||||||
|
</source>
|
||||||
|
<target>
|
||||||
|
<path>/dev/zvol/nvme/vhds</path>
|
||||||
|
</target>
|
||||||
|
</pool>
|
Loading…
Reference in New Issue
Block a user