Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
e5ef5e29
Commit
e5ef5e29
authored
Nov 15, 2013
by
Matthias Vogelgesang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add system module to blacklist kernel module
parent
009fdbf9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
141 additions
and
0 deletions
+141
-0
library/system/blacklist
+141
-0
No files found.
library/system/blacklist
0 → 100644
View file @
e5ef5e29
#!/usr/bin/python
# encoding: utf-8 -*-
# (c) 2013, Matthias Vogelgesang <matthias.vogelgesang@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
os
import
re
DOCUMENTATION
=
'''
---
module: blacklist
author: Matthias Vogelgesang
version_added: 1.4
short_description: Blacklist kernel modules
description:
- Add or remove kernel modules from blacklist.
options:
name:
required: true
description:
- Name of kernel module to black- or whitelist.
state:
required: false
default: "present"
choices: [ present, absent ]
description:
- Whether the module should be present in the blacklist or absent.
blacklist_file:
required: false
description:
- If specified, use this blacklist file instead of
C(/etc/modprobe.d/blacklist-ansible.conf).
default: null
requirements: []
'''
EXAMPLES
=
'''
# Blacklist the nouveau driver module
- blacklist: name=nouveau state=present
'''
class
Blacklist
(
object
):
def
__init__
(
self
,
module
,
filename
):
if
not
os
.
path
.
exists
(
filename
):
open
(
filename
,
'a'
)
.
close
()
self
.
filename
=
filename
self
.
module
=
module
def
get_pattern
(
self
):
return
'^blacklist
\
s*'
+
self
.
module
+
'$'
def
readlines
(
self
):
f
=
open
(
self
.
filename
,
'r'
)
lines
=
f
.
readlines
()
f
.
close
()
return
lines
def
module_listed
(
self
):
lines
=
self
.
readlines
()
pattern
=
self
.
get_pattern
()
for
line
in
lines
:
stripped
=
line
.
strip
()
if
stripped
.
startswith
(
'#'
):
continue
if
re
.
match
(
pattern
,
stripped
):
return
True
return
False
def
remove_module
(
self
):
lines
=
self
.
readlines
()
pattern
=
self
.
get_pattern
()
f
=
open
(
self
.
filename
,
'w'
)
for
line
in
lines
:
if
not
re
.
match
(
pattern
,
line
.
strip
()):
f
.
write
(
line
)
f
.
close
()
def
add_module
(
self
):
f
=
open
(
self
.
filename
,
'a'
)
f
.
write
(
'blacklist
%
s
\n
'
%
self
.
module
)
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
name
=
dict
(
required
=
True
),
state
=
dict
(
required
=
False
,
choices
=
[
'present'
,
'absent'
],
default
=
'present'
),
blacklist_file
=
dict
(
required
=
False
,
default
=
None
)
),
supports_check_mode
=
False
,
)
args
=
dict
(
changed
=
False
,
failed
=
False
,
name
=
module
.
params
[
'name'
],
state
=
module
.
params
[
'state'
])
filename
=
'/etc/modprobe.d/blacklist-ansible.conf'
if
module
.
params
[
'blacklist_file'
]:
filename
=
module
.
params
[
'blacklist_file'
]
blacklist
=
Blacklist
(
args
[
'name'
],
filename
)
if
blacklist
.
module_listed
():
if
args
[
'state'
]
==
'absent'
:
blacklist
.
remove_module
()
args
[
'changed'
]
=
True
else
:
if
args
[
'state'
]
==
'present'
:
blacklist
.
add_module
()
args
[
'changed'
]
=
True
module
.
exit_json
(
**
args
)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment