hypervisor refinement
This commit is contained in:
21
ansible/roles/hypervisor_old/defaults/main.yml
Normal file
21
ansible/roles/hypervisor_old/defaults/main.yml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
libvirt_server_packages:
|
||||
- qemu-base
|
||||
- libvirt
|
||||
- bridge-utils
|
||||
- openbsd-netcat
|
||||
- edk2-ovmf
|
||||
- swtpm
|
||||
- libvirt-python
|
||||
- python-lxml
|
||||
|
||||
libvirt_zfs_pool_name: zfs
|
||||
libvirt_zfs_pool_path: ssd/vhds
|
||||
|
||||
libvirt_iso_pool_name: iso
|
||||
libvirt_iso_pool_path: /iso
|
||||
|
||||
libvirt_qcow_pool_name: qcow
|
||||
libvirt_qcow_pool_path: /qcow
|
||||
|
||||
libvirt_cluster_network_name: cluster
|
136
ansible/roles/hypervisor_old/tasks/main.yml
Normal file
136
ansible/roles/hypervisor_old/tasks/main.yml
Normal file
@ -0,0 +1,136 @@
|
||||
---
|
||||
- name: Install libvirt server packages
|
||||
become: true
|
||||
community.general.pacman:
|
||||
name: "{{ libvirt_server_packages }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
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: true
|
||||
|
||||
- name: Remove default libvirt network
|
||||
community.libvirt.virt_net:
|
||||
name: default
|
||||
state: absent
|
||||
|
||||
- name: create libvirt zfs dataset
|
||||
community.general.zfs:
|
||||
name: "{{ libvirt_zfs_pool_path }}"
|
||||
state: present
|
||||
extra_zfs_properties:
|
||||
canmount: off
|
||||
mountpoint: none
|
||||
compression: off
|
||||
primarycache: metadata
|
||||
secondarycache: none
|
||||
reservation: none
|
||||
refreservation: none
|
||||
dedup: off
|
||||
encryption: off
|
||||
volmode: dev
|
||||
devices: off
|
||||
atime: off
|
||||
|
||||
- name: set zfs pool variables
|
||||
set_fact:
|
||||
libvirt_pool_type: zfs
|
||||
libvirt_pool_name: "{{ libvirt_zfs_pool_name }}"
|
||||
libvirt_pool_source: "{{ libvirt_zfs_pool_path }}"
|
||||
libvirt_pool_target: ""
|
||||
|
||||
- name: define zfs storage pool
|
||||
community.libvirt.virt_pool:
|
||||
name: "{{ libvirt_zfs_pool_name }}"
|
||||
command: define
|
||||
xml: '{{ lookup("template", "pool.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: set iso pool variables
|
||||
set_fact:
|
||||
libvirt_pool_type: dir
|
||||
libvirt_pool_name: "{{ libvirt_iso_pool_name }}"
|
||||
libvirt_pool_source: ""
|
||||
libvirt_pool_target: "{{ libvirt_iso_pool_path }}"
|
||||
|
||||
- name: create iso storage dir
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: "{{ libvirt_iso_pool_path }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: libvirt
|
||||
mode: 0775
|
||||
|
||||
- name: define iso storage pool
|
||||
community.libvirt.virt_pool:
|
||||
name: "{{ libvirt_iso_pool_name }}"
|
||||
command: define
|
||||
xml: '{{ lookup("template", "pool.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: set iso pool variables
|
||||
set_fact:
|
||||
libvirt_pool_type: dir
|
||||
libvirt_pool_name: "{{ libvirt_qcow_pool_name }}"
|
||||
libvirt_pool_source: ""
|
||||
libvirt_pool_target: "{{ libvirt_qcow_pool_path }}"
|
||||
|
||||
- name: create qcow storage dir
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: "{{ libvirt_qcow_pool_path }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: libvirt
|
||||
mode: 0775
|
||||
|
||||
- name: define qcow storage pool
|
||||
community.libvirt.virt_pool:
|
||||
name: "{{ libvirt_qcow_pool_name }}"
|
||||
command: define
|
||||
xml: '{{ lookup("template", "pool.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
|
4
ansible/roles/hypervisor_old/templates/network.xml.j2
Normal file
4
ansible/roles/hypervisor_old/templates/network.xml.j2
Normal file
@ -0,0 +1,4 @@
|
||||
<network>
|
||||
<name>{{ libvirt_network_name }}</name>
|
||||
<domain name="{{ libvirt_network_domain }}"/>
|
||||
</network>
|
9
ansible/roles/hypervisor_old/templates/pool.xml.j2
Normal file
9
ansible/roles/hypervisor_old/templates/pool.xml.j2
Normal file
@ -0,0 +1,9 @@
|
||||
<pool type="{{ libvirt_pool_type }}">
|
||||
<name>{{ libvirt_pool_name }}</name>
|
||||
<source>
|
||||
<name>{{ libvirt_pool_source }}</name>
|
||||
</source>
|
||||
<target>
|
||||
<path>{{ libvirt_pool_target }}</path>
|
||||
</target>
|
||||
</pool>
|
Reference in New Issue
Block a user