mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
kernel_blacklist: bugfix (#7382)
* kernel_blacklist: bugfix * add fix + changelog frag * skip aix,freebsd,macos,osx in integration test * Update changelogs/fragments/7382-kernel-blacklist-bugfix.yml Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
eb4f8d4301
commit
33133f3ba9
5 changed files with 64 additions and 23 deletions
2
changelogs/fragments/7382-kernel-blacklist-bugfix.yml
Normal file
2
changelogs/fragments/7382-kernel-blacklist-bugfix.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- kernel_blacklist - simplified the mechanism to update the file, fixing the error (https://github.com/ansible-collections/community.general/pull/7382, https://github.com/ansible-collections/community.general/issues/7362).
|
|
@ -53,7 +53,6 @@ EXAMPLES = '''
|
|||
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
||||
|
||||
|
@ -106,16 +105,10 @@ class Blacklist(StateModuleHelper):
|
|||
|
||||
def __quit_module__(self):
|
||||
if self.has_changed() and not self.module.check_mode:
|
||||
dummy, tmpfile = tempfile.mkstemp()
|
||||
try:
|
||||
os.remove(tmpfile)
|
||||
self.module.preserved_copy(self.vars.filename, tmpfile) # ensure right perms/ownership
|
||||
with open(tmpfile, 'w') as fd:
|
||||
bkp = self.module.backup_local(self.vars.filename)
|
||||
with open(self.vars.filename, "w") as fd:
|
||||
fd.writelines(["{0}\n".format(x) for x in self.vars.lines])
|
||||
self.module.atomic_move(tmpfile, self.vars.filename)
|
||||
finally:
|
||||
if os.path.exists(tmpfile):
|
||||
os.remove(tmpfile)
|
||||
self.module.add_cleanup_file(bkp)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -3,3 +3,7 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/1
|
||||
skip/aix
|
||||
skip/freebsd
|
||||
skip/osx
|
||||
skip/macos
|
||||
|
|
10
tests/integration/targets/kernel_blacklist/handlers/main.yml
Normal file
10
tests/integration/targets/kernel_blacklist/handlers/main.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Remove modprobe.d
|
||||
ansible.builtin.file:
|
||||
path: /etc/modprobe.d
|
||||
state: absent
|
||||
|
|
@ -107,7 +107,7 @@
|
|||
src: '{{ bl_file }}'
|
||||
register: slurp_test_3
|
||||
|
||||
- name: assert element is added
|
||||
- name: assert element is removed
|
||||
assert:
|
||||
that:
|
||||
- bl_test_3 is changed
|
||||
|
@ -121,3 +121,35 @@
|
|||
blacklist aaaa
|
||||
blacklist cccc
|
||||
blacklist dddd
|
||||
|
||||
############################################################################################################################################
|
||||
#
|
||||
# Issue 7362
|
||||
#
|
||||
|
||||
- name: Create /etc/modprobe.d
|
||||
ansible.builtin.file:
|
||||
path: /etc/modprobe.d
|
||||
state: directory
|
||||
mode: '0755'
|
||||
owner: root
|
||||
group: root
|
||||
notify: Remove modprobe.d
|
||||
|
||||
- name: Create cls_rsvp file
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/modprobe.d/cls_rsvp-blacklist.conf
|
||||
content: |
|
||||
blacklist cls_rsvp
|
||||
mode: '0644'
|
||||
|
||||
- name: Block potentially affected (and unused) modules (7362)
|
||||
community.general.kernel_blacklist:
|
||||
name: "{{ line_item }}"
|
||||
state: present
|
||||
blacklist_file: "/etc/modprobe.d/{{ line_item }}-blacklist.conf"
|
||||
with_items:
|
||||
- cifs
|
||||
- cls_rsvp
|
||||
loop_control:
|
||||
loop_var: line_item
|
||||
|
|
Loading…
Reference in a new issue