diff --git a/Manual.org b/Manual.org index 4b3b994..a19a5e9 100644 --- a/Manual.org +++ b/Manual.org @@ -2701,13 +2701,22 @@ preferred_refreshrates: # unloading the drivers using the modprobe module does not work for some strange reason... - name: unload kms drivers - command: rmmod '{{ item }}' + rmmod: + name: '{{ item }}' loop: - nouveau - ttm - drm_kms_helper - drm - ignore_errors: yes + + #- name: unload kms drivers + # command: rmmod '{{ item }}' + # loop: + # - nouveau + # - ttm + # - drm_kms_helper + # - drm + # ignore_errors: yes - name: load nvidia driver modprobe: @@ -7297,6 +7306,8 @@ if __name__ == '__main__': - [ ] support multiple screens (-d :0.0 .. :0.n) #+INCLUDE: "library/xrandr_facts.py" src python +** rmmod.py +#+INCLUDE: library/rmmod.py src python * Handlers :PROPERTIES: :ID: e90af299-d84f-4924-803f-5644509c0a2f diff --git a/library/rmmod.py b/library/rmmod.py new file mode 100644 index 0000000..8254690 --- /dev/null +++ b/library/rmmod.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Copyright: (c) 2019, Alexander Grothe +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type +import traceback + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = ''' +--- +module: rmmod +short_description: unload kernel modules with rmmod +version_added: 2.7 +author: + - Alexander Grothe +description: + - Unload kernel modules with rmmod. + - Builtin kernel modules can't be removed (will do nothing in this case). +options: + name: + required: true + description: + - Name of kernel module to remove. +''' + +EXAMPLES = ''' +- name: Unload nouveau module + rmmod: + name: nouveau +''' + + +def main(): + module = AnsibleModule( + argument_spec=dict( + name=dict(type='str', required=True), + ), + supports_check_mode=True, + ) + + name = module.params['name'] + + # FIXME: Adding all parameters as result values is useless + result = dict( + changed=False, + name=name, + ) + + # Check if module is loaded + try: + is_loaded = False + with open('/proc/modules') as modules: + module_name = name.replace('-', '_') + ' ' + for line in modules: + if line.startswith(module_name): + is_loaded = True + break + except IOError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc(), **result) + + # remove module if it is loaded + if is_loaded: + if not module.check_mode: + rc, out, err = module.run_command([module.get_bin_path('rmmod', True), name]) + if rc != 0: + module.fail_json(msg=err, rc=rc, stdout=out, stderr=err, **result) + result['changed'] = True + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/roles/yavdr-xorg/tasks/detect-xorg.yml b/roles/yavdr-xorg/tasks/detect-xorg.yml index 63da2f4..0562860 100644 --- a/roles/yavdr-xorg/tasks/detect-xorg.yml +++ b/roles/yavdr-xorg/tasks/detect-xorg.yml @@ -56,13 +56,22 @@ # unloading the drivers using the modprobe module does not work for some strange reason... - name: unload kms drivers - command: rmmod '{{ item }}' + rmmod: + name: '{{ item }}' loop: - nouveau - ttm - drm_kms_helper - drm - ignore_errors: yes + + #- name: unload kms drivers + # command: rmmod '{{ item }}' + # loop: + # - nouveau + # - ttm + # - drm_kms_helper + # - drm + # ignore_errors: yes - name: load nvidia driver modprobe: