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
27a08dc6
Commit
27a08dc6
authored
Sep 18, 2013
by
David Stygstra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Module to manage kernel modules
parent
503f0625
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
+93
-0
library/system/modprobe
+93
-0
No files found.
library/system/modprobe
0 → 100755
View file @
27a08dc6
#!/usr/bin/env python2
#coding: utf-8 -*-
# This module 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.
#
# This software 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 this software. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION
=
'''
---
module: modprobe
short_description: Add or remove kernel modules
requirements: []
description:
- Add or remove kernel modules.
options:
name:
required: true
description:
- Name of kernel module to manage.
state:
required: false
default: "present"
choices: [ present, absent ]
description:
- Whether the module should be present or absent.
'''
EXAMPLES
=
'''
# Add the 802.1q module
- modprobe: name=8021q state=present
'''
def
main
():
module
=
AnsibleModule
(
argument_spec
=
{
'name'
:
{
'required'
:
True
},
'state'
:
{
'default'
:
'present'
,
'choices'
:
[
'present'
,
'absent'
]},
},
supports_check_mode
=
True
,
)
args
=
{
'changed'
:
False
,
'failed'
:
False
,
'name'
:
module
.
params
[
'name'
],
'state'
:
module
.
params
[
'state'
],
}
# Check if module is present
try
:
with
open
(
'/proc/modules'
)
as
modules
:
present
=
any
(
module
.
startswith
(
args
[
'name'
]
+
' '
)
for
module
in
modules
)
except
IOError
as
e
:
module
.
fail_json
(
msg
=
str
(
e
),
**
args
)
# Check only; don't modify
if
module
.
check_mode
:
if
args
[
'state'
]
==
'present'
and
not
present
:
changed
=
True
elif
args
[
'state'
]
==
'absent'
and
present
:
changed
=
True
else
:
changed
=
False
module
.
exit_json
(
changed
=
changed
)
# Add/remove module as needed
if
args
[
'state'
]
==
'present'
:
if
not
present
:
rc
,
_
,
err
=
module
.
run_command
([
'modprobe'
,
args
[
'name'
]])
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
,
**
args
)
args
[
'changed'
]
=
True
elif
args
[
'state'
]
==
'absent'
:
if
present
:
rc
,
_
,
err
=
module
.
run_command
([
'rmmod'
,
args
[
'name'
]])
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
,
**
args
)
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