Skip to content

Commit 20708e9

Browse files
committed
Add support for specfying vfio id's
1 parent 1fabb79 commit 20708e9

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

roles/iommu/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,19 @@
2020
become: true
2121
2222
```
23+
24+
Or if you want the node to reboot automatically
25+
26+
```
27+
---
28+
- name: Enable IOMMU
29+
hosts: iommu
30+
tasks:
31+
- import_role:
32+
name: stackhpc.linux.iommu
33+
handlers:
34+
- name: reboot
35+
reboot:
36+
become: true
37+
38+
```

roles/iommu/handlers/main.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Regenerate initramfs
3+
ansible.builtin.shell: |-
4+
#!/bin/bash
5+
set -eux
6+
dracut -v -f /boot/initramfs-$(uname -r).img $(uname -r)
7+
become: true
8+
changed_when: true

roles/iommu/tasks/main.yml

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
---
2+
- name: Template dracut config for vfio
3+
ansible.builtin.blockinfile:
4+
path: /etc/dracut.conf.d/gpu-vfio.conf
5+
block: |
6+
add_drivers+="vfio vfio_iommu_type1 vfio_pci vfio_virqfd"
7+
owner: root
8+
group: root
9+
mode: "0660"
10+
create: true
11+
become: true
12+
when: iommu_vfio_pci_ids is defined
13+
notify:
14+
- Regenerate initramfs
15+
- reboot
16+
17+
- name: Add vfio to modules-load.d
18+
ansible.builtin.blockinfile:
19+
path: /etc/modules-load.d/vfio.conf
20+
block: |
21+
vfio
22+
vfio_iommu_type1
23+
vfio_pci
24+
vfio_virqfd
25+
owner: root
26+
group: root
27+
mode: "0664"
28+
create: true
29+
become: true
30+
when: iommu_vfio_pci_ids is defined
31+
notify: reboot
32+
233
- name: Add iommu to kernel command line (Intel)
334
ansible.builtin.include_role:
435
name: stackhpc.linux.grubcmdline
536
vars:
6-
kernel_cmdline: # noqa: var-naming[no-role-prefix]
7-
- intel_iommu=on
37+
kernel_cmdline: "{{ ['intel_iommu=on'] + (['vfio-pci.ids=' + iommu_vfio_pci_ids] if iommu_vfio_pci_ids is defined else []) }}" # noqa: var-naming[no-role-prefix]
838
kernel_cmdline_remove: # noqa: var-naming[no-role-prefix]
939
- ^intel_iommu=
40+
- ^vfio-pci\.ids=
1041
when: ansible_facts.processor | select('search', 'Intel') | list | length > 0
1142

1243
- name: Set iommu=pt

0 commit comments

Comments
 (0)