1
0
IaC/ansible/roles/hypervisor_zfs/tasks/main.yml

136 lines
3.3 KiB
YAML
Raw Normal View History

2022-09-04 08:33:46 -04:00
---
2023-08-09 01:49:23 -04:00
- name: Install libvirt server packages
2022-09-04 08:33:46 -04:00
become: true
community.general.pacman:
name: "{{ libvirt_server_packages }}"
2023-08-09 01:49:23 -04:00
state: present
2022-09-04 08:33:46 -04:00
update_cache: true
when:
- ansible_os_family == 'Arch'
2023-08-09 01:49:23 -04:00
- name: Add user to libvirt group
2022-09-04 08:33:46 -04:00
become: true
ansible.builtin.user:
name: "{{ ansible_user }}"
groups: libvirt
append: true
2023-08-09 01:49:23 -04:00
- name: Start and enable libvirt service
2022-09-04 08:33:46 -04:00
become: true
ansible.builtin.service:
name: libvirtd.service
state: started
2023-08-09 01:49:23 -04:00
enabled: true
2022-09-04 08:33:46 -04:00
2023-08-09 01:49:23 -04:00
- name: Remove default libvirt network
2022-09-04 23:28:28 -04:00
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:
2022-09-05 05:27:26 -04:00
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: ""
2022-09-04 23:28:28 -04:00
2022-09-04 08:33:46 -04:00
- name: define zfs storage pool
community.libvirt.virt_pool:
name: "{{ libvirt_zfs_pool_name }}"
command: define
2022-09-04 23:28:28 -04:00
xml: '{{ lookup("template", "pool.xml.j2") }}'
2022-09-04 08:33:46 -04:00
2022-09-05 05:27:26 -04:00
# - name: build zfs storage pool
# community.libvirt.virt_pool:
# name: "{{ libvirt_zfs_pool_name }}"
# command: build
2022-09-04 08:33:46 -04:00
- name: start zfs storage pool
community.libvirt.virt_pool:
name: "{{ libvirt_zfs_pool_name }}"
state: active
autostart: true
2022-09-05 05:27:26 -04:00
- 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 }}"
2022-09-04 23:28:28 -04:00
- name: create iso storage dir
become: true
ansible.builtin.file:
path: "{{ libvirt_iso_pool_path }}"
state: directory
owner: root
group: libvirt
mode: 0775
2022-09-04 08:33:46 -04:00
- name: define iso storage pool
community.libvirt.virt_pool:
name: "{{ libvirt_iso_pool_name }}"
command: define
2022-09-04 23:28:28 -04:00
xml: '{{ lookup("template", "pool.xml.j2") }}'
2022-09-04 08:33:46 -04:00
- 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
2022-09-05 05:27:26 -04:00
- 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 }}"
2022-09-04 23:28:28 -04:00
- name: create qcow storage dir
become: true
ansible.builtin.file:
path: "{{ libvirt_qcow_pool_path }}"
state: directory
owner: root
group: libvirt
mode: 0775
2022-09-04 08:33:46 -04:00
- name: define qcow storage pool
community.libvirt.virt_pool:
name: "{{ libvirt_qcow_pool_name }}"
command: define
2022-09-04 23:28:28 -04:00
xml: '{{ lookup("template", "pool.xml.j2") }}'
2022-09-04 08:33:46 -04:00
- 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