2022-02-26 17:46:02 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Read cpuinfo from kernel
|
2023-02-08 17:23:50 +00:00
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: cat /proc/cpuinfo
|
2022-02-26 17:46:02 +00:00
|
|
|
register: cpu_info
|
|
|
|
changed_when: false
|
|
|
|
|
2022-02-26 17:58:51 +00:00
|
|
|
- name: Verify if Intel VMX or AMD SVM is enabled
|
2023-02-08 17:23:50 +00:00
|
|
|
ansible.builtin.fail:
|
2022-02-26 17:58:51 +00:00
|
|
|
msg: "Intel VMX or AMD SVE not enabled"
|
|
|
|
when: "'vmx' not in cpu_info.stdout and 'svm' not in cpu_info.stdout"
|
2022-02-26 17:46:02 +00:00
|
|
|
|
2022-12-28 21:02:46 +00:00
|
|
|
- name: Include OS-specific variables
|
2023-02-12 13:46:34 +00:00
|
|
|
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
|
2022-02-26 17:46:02 +00:00
|
|
|
|
2022-03-11 11:48:06 +00:00
|
|
|
- name: Add virt-manager to list of kvm packages
|
2023-02-08 17:23:50 +00:00
|
|
|
ansible.builtin.set_fact:
|
2022-02-26 17:46:02 +00:00
|
|
|
kvm_package_names: "{{ kvm_package_names + kvm_vm_manager_package_names }}"
|
|
|
|
when: kvm_virtual_machine_manager
|
|
|
|
|
2022-03-11 11:48:06 +00:00
|
|
|
- name: Install kvm packages
|
2023-02-08 17:23:50 +00:00
|
|
|
ansible.builtin.package:
|
2022-02-26 17:46:02 +00:00
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
with_items:
|
|
|
|
- "{{ kvm_package_names }}"
|
|
|
|
|
|
|
|
- name: Load and persist kernel module "kvm_amd"
|
|
|
|
when: cpu_info.stdout.find('sev') != -1
|
|
|
|
block:
|
|
|
|
- name: Load kernel module "kvm_amd" temporarily
|
2023-02-08 17:23:50 +00:00
|
|
|
community.general.modprobe:
|
2022-02-26 17:46:02 +00:00
|
|
|
name: "kvm_amd"
|
|
|
|
params: "sev=1"
|
|
|
|
state: present
|
|
|
|
- name: Load kernel module "kvm_amd" persistently
|
2023-02-08 17:23:50 +00:00
|
|
|
ansible.builtin.template:
|
2022-02-26 17:46:02 +00:00
|
|
|
src: "etc/modules-load.d/10-amd-sve.conf.j2"
|
|
|
|
dest: "/etc/modules-load.d/10-amd-sve.conf"
|
|
|
|
owner: root
|
|
|
|
group: root
|
2023-02-26 21:20:44 +00:00
|
|
|
mode: "0644"
|
2022-02-26 17:46:02 +00:00
|
|
|
|
2022-03-11 11:48:06 +00:00
|
|
|
- name: Append unix user to unix groups to interact with qemu/kvm
|
2023-02-08 17:23:50 +00:00
|
|
|
ansible.builtin.user:
|
2022-02-26 17:46:02 +00:00
|
|
|
name: "{{ item.name }}"
|
2023-02-08 17:23:50 +00:00
|
|
|
append: true
|
2022-02-26 17:46:02 +00:00
|
|
|
groups: "{{ kvm_unix_groups }}"
|
|
|
|
with_items: "{{ kvm_users }}"
|
|
|
|
|
|
|
|
- name: Start and enable {{ kvm_service_name }}
|
2023-02-08 17:23:50 +00:00
|
|
|
ansible.builtin.systemd:
|
2022-02-26 17:46:02 +00:00
|
|
|
name: "{{ kvm_service_name }}"
|
|
|
|
state: started
|
2023-02-08 17:23:50 +00:00
|
|
|
enabled: true
|