|
1 | 1 | --- |
2 | | -# GPU Group Configuration for VirGL/virtio-gl Acceleration |
3 | | -# Ensures all non-system users can access GPU render nodes for hardware acceleration |
4 | | -# Without this, gnome-remote-desktop sessions fall back to software rendering (CPU-intensive) |
| 2 | +# GPU Access Configuration for VirGL/virtio-gl Acceleration |
| 3 | +# Uses udev rule to make /dev/dri/* world-readable (mode 0666). |
| 4 | +# Any process can access the GPU without needing render/video group membership. |
| 5 | +# |
| 6 | +# Conditional: only runs if /dev/dri exists (GPU present). |
| 7 | +# Works for both VirGL (VM) and physical GPUs (AMD/NVIDIA). |
5 | 8 |
|
6 | 9 | # ============================================================================ |
7 | | -# ENSURE GPU GROUPS EXIST |
| 10 | +# DETECT GPU PRESENCE |
8 | 11 | # ============================================================================ |
9 | 12 |
|
10 | | -- name: Ensure render group exists |
11 | | - ansible.builtin.group: |
12 | | - name: render |
13 | | - state: present |
14 | | - system: true |
15 | | - when: |
16 | | - - ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
17 | | - - has_gnome |
18 | | - |
19 | | -- name: Ensure video group exists |
20 | | - ansible.builtin.group: |
21 | | - name: video |
22 | | - state: present |
23 | | - system: true |
| 13 | +- name: Check if /dev/dri exists (GPU present) |
| 14 | + ansible.builtin.stat: |
| 15 | + path: /dev/dri |
| 16 | + register: dri_device |
24 | 17 | when: |
25 | 18 | - ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
26 | 19 | - has_gnome |
27 | 20 |
|
28 | 21 | # ============================================================================ |
29 | | -# ADD ALL NON-SYSTEM USERS TO GPU GROUPS |
| 22 | +# UDEV RULE FOR WORLD-READABLE GPU DEVICES |
30 | 23 | # ============================================================================ |
31 | 24 |
|
32 | | -- name: Get list of non-system users (UID 1000-60000) |
33 | | - ansible.builtin.shell: |
34 | | - cmd: "awk -F: '$3 >= 1000 && $3 < 60000 && $1 != \"nobody\" {print $1}' /etc/passwd" |
35 | | - register: non_system_users |
36 | | - changed_when: false |
37 | | - when: |
38 | | - - ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
39 | | - - has_gnome |
40 | | - |
41 | | -- name: Add non-system users to render and video groups |
42 | | - ansible.builtin.user: |
43 | | - name: "{{ item }}" |
44 | | - groups: |
45 | | - - render |
46 | | - - video |
47 | | - append: true |
48 | | - loop: "{{ non_system_users.stdout_lines | default([]) }}" |
| 25 | +- name: Deploy udev rule for GPU device permissions |
| 26 | + ansible.builtin.copy: |
| 27 | + dest: /etc/udev/rules.d/99-gpu-open-access.rules |
| 28 | + mode: "0644" |
| 29 | + content: | |
| 30 | + # Allow all processes GPU access without render/video group membership |
| 31 | + # Managed by Ansible (dfe-developer rdp role) |
| 32 | + SUBSYSTEM=="drm", MODE="0666" |
49 | 33 | when: |
50 | 34 | - ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
51 | 35 | - has_gnome |
52 | | - - non_system_users.stdout_lines is defined |
53 | | - - non_system_users.stdout_lines | length > 0 |
| 36 | + - dri_device.stat.exists | default(false) |
| 37 | + notify: reload udev rules |
54 | 38 |
|
55 | 39 | # ============================================================================ |
56 | 40 | # VERIFY GPU ACCESS |
|
63 | 47 | when: |
64 | 48 | - ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
65 | 49 | - has_gnome |
| 50 | + - dri_device.stat.exists | default(false) |
66 | 51 |
|
67 | | -- name: Display GPU group configuration status |
| 52 | +- name: Display GPU configuration status |
68 | 53 | ansible.builtin.debug: |
69 | 54 | msg: | |
70 | | - GPU Groups configured for VirGL acceleration: |
71 | | - - Users added to render/video groups: {{ non_system_users.stdout_lines | default([]) | join(', ') }} |
72 | | - - Render device (/dev/dri/renderD128): {{ 'PRESENT' if render_device.stat.exists | default(false) else 'NOT FOUND (not a VM or no virtio-gl)' }} |
| 55 | + GPU access configured via udev rule (world-readable): |
| 56 | + - Rule: /etc/udev/rules.d/99-gpu-open-access.rules |
| 57 | + - /dev/dri: PRESENT |
| 58 | + - Render device (/dev/dri/renderD128): {{ 'PRESENT' if render_device.stat.exists | default(false) else 'NOT FOUND' }} |
73 | 59 |
|
74 | | - Note: Users must log out and back in for group changes to take effect. |
75 | | - For RDP sessions, restart gnome-remote-desktop: systemctl restart gnome-remote-desktop |
| 60 | + All processes can access GPU devices without group membership. |
| 61 | + when: |
| 62 | + - ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
| 63 | + - has_gnome |
| 64 | + - dri_device.stat.exists | default(false) |
| 65 | + |
| 66 | +- name: Display GPU skipped status |
| 67 | + ansible.builtin.debug: |
| 68 | + msg: "No GPU detected (/dev/dri not present) - skipping GPU configuration" |
76 | 69 | when: |
77 | 70 | - ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
78 | 71 | - has_gnome |
| 72 | + - not (dri_device.stat.exists | default(false)) |
0 commit comments