yavdr-ansible/roles/yavdr-xorg/tasks/detect-xorg.yml
Alexander Grothe 3ebd5df3cb Cleanup
2019-05-09 11:40:51 +02:00

189 lines
4.5 KiB
YAML

---
# file: roles/yavdr-xorg/tasks/detect-xorg.yml
- name: "expand template for x-verbose@.service"
template:
src: "templates/systemd/system/x-verbose@.service.j2"
dest: "/etc/systemd/system/x-verbose@.service"
- name: "expand template for xorg-verbose.conf"
template:
src: "templates/xorg-verbose.conf.j2"
dest: "/etc/X11/xorg-verbose.conf"
- name: "remove intel snippet"
file:
path: /etc/X11/xorg.conf.d/20-intel.conf
state: absent
- name: Stop VDR
systemd:
name: vdr.service
state: stopped
enabled: yes
notify: ['Start VDR']
- name: Stop yavdr-xorg
systemd:
name: 'yavdr-xorg'
state: stopped
enabled: yes
notify: ['Start yavdr-xorg']
- name: Stop xlogin
systemd:
name: 'xlogin@{{ vdr.user }}.service'
state: stopped
notify: ['Start xlogin']
- name: Stop x
systemd:
name: x@vt7.service
state: stopped
- name: check if a nvidia driver has been installed
set_fact:
nvidia_driver_installed: '{{ "nvidia" in lookup("file", "/etc/yavdr/autoinstalled") }}'
- name: unload nouveau driver, replace with nvidia
block:
- name: unbind vconsole
shell: echo 0 > /sys/class/vtconsole/vtcon1/bind
- name: "wait a little, so noveau isn't used anymore"
wait_for:
timeout: 1
# unloading the drivers using the modprobe module does not work for some strange reason...
- name: unload kms drivers
rmmod:
name: '{{ item }}'
loop:
- nouveau
- ttm
- drm_kms_helper
- drm
- name: load nvidia driver
modprobe:
name: "nvidia"
state: present
- name: "wait a little before starting nvidia-persistenced"
wait_for:
timeout: 1
- name: start nvidia-persistenced
systemd:
name: "nvidia-persistenced"
state: started
enabled: true
masked: false
daemon_reload: true
when:
- nvidia_detected
- nvidia_driver_installed
- '"nouveau" in modules'
- name: "start x-verbose@.service"
systemd:
name: "x-verbose@vt7.service"
state: started
enabled: false
masked: false
daemon_reload: true
- name: "wait a little, so X has some time to start up"
wait_for:
timeout: 3
- name: "detect xorg configuration"
xrandr_facts:
preferred_refreshrates: '{{ preferred_refreshrates }}'
preferred_resolutions: '{{ preferred_resolutions }}'
preferred_outputs: '{{ preferred_outputs }}'
- debug:
var: xorg.primary
- debug:
var: xorg.secondary
when: xorg.secondary is defined
- debug:
var: drm
when: drm is defined
- name: "stop x-verbose@vt7.service"
systemd:
name: "x-verbose@vt7.service"
state: stopped
enabled: false
masked: true
#- name: "wait a little bit, so X has some time to shut down (needed?)"
# wait_for:
# timeout: 3
- name: save results
block:
- name: ensure facts.d directory exists
file:
state: directory
path: /etc/ansible/facts.d
- name: write xorg variable as local fact
copy:
content: '{{ {"xorg": xorg} | to_nice_json }}'
dest: /etc/ansible/facts.d/xorg.fact
- name: write xrandr variable as local fact
copy:
content: '{{ {"xrandr": xrandr} | to_nice_json }}'
dest: /etc/ansible/facts.d/xrandr.fact
- name: write drm variable as local fact
copy:
content: '{{ {"drm": drm} | to_nice_json }}'
dest: /etc/ansible/facts.d/drm.fact
when:
- xrandr is defined
- xorg is defined
- drm is defined
- name: update xorg, xrandr and drm variables with values from local facts if needed
set_fact:
xorg: '{{ ansible_local.xorg.xorg }}'
xrandr: '{{ ansible_local.xrandr.xrandr }}'
drm: '{{ ansible_local.drm.drm }}'
when:
- xrandr is undefined
- xorg is undefined
- drm is undefined
# TODO: expand template for xorg.conf (or snippets)
# with respect for the available graphics card driver
# nvidia, noveau, intel, radeon
- name: nvidia related config
block:
- name: create xorg.conf (for nvidia driver)
template:
src: templates/xorg.conf.j2
dest: /etc/X11/xorg.conf
backup: yes
when:
- nvidia_detected
- name: intel xorg config snippet
template:
src: templates/20-intel.conf.j2
dest: /etc/X11/xorg.conf.d/20-intel.conf
when:
- intel_detected and not nvidia_detected
- name: server flags config snippet to disable screen blanking
template:
src: templates/10-serverflags.conf.j2
dest: /etc/X11/xorg.conf.d/10-serverflags.conf