Skip to content

Commit

Permalink
seboolean: PEP8 compliancy and doc fixes (ansible#30888)
Browse files Browse the repository at this point in the history
This PR includes:
- PEP8 compliancy fixes
- Documentation fixes
  • Loading branch information
dagwieers authored Oct 30, 2017
1 parent 32775b0 commit edc0ff4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
55 changes: 29 additions & 26 deletions lib/ansible/modules/system/seboolean.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
#!/usr/bin/python

# (c) 2012, Stephen Fromm <[email protected]>
# Copyright: (c) 2012, Stephen Fromm <[email protected]>
# 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


ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'core'}


DOCUMENTATION = '''
---
module: seboolean
short_description: Toggles SELinux booleans.
short_description: Toggles SELinux booleans
description:
- Toggles SELinux booleans.
version_added: "0.7"
options:
name:
description:
- Name of the boolean to configure
- Name of the boolean to configure.
required: true
default: null
persistent:
description:
- Set to C(yes) if the boolean setting should survive a reboot
required: false
default: no
choices: [ "yes", "no" ]
- Set to C(yes) if the boolean setting should survive a reboot.
type: bool
default: 'no'
state:
description:
- Desired boolean value
type: bool
required: true
default: null
choices: [ 'yes', 'no' ]
notes:
- Not tested on any debian based system
requirements: [ libselinux-python, libsemanage-python ]
author: "Stephen Fromm (@sfromm)"
- Not tested on any Debian based system.
requirements:
- libselinux-python
- libsemanage-python
author:
- Stephen Fromm (@sfromm)
'''

EXAMPLES = '''
Expand All @@ -55,15 +53,15 @@

try:
import selinux
HAVE_SELINUX=True
HAVE_SELINUX = True
except ImportError:
HAVE_SELINUX=False
HAVE_SELINUX = False

try:
import semanage
HAVE_SEMANAGE=True
HAVE_SEMANAGE = True
except ImportError:
HAVE_SEMANAGE=False
HAVE_SEMANAGE = False

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import binary_type
Expand All @@ -86,6 +84,7 @@ def has_boolean_value(module, name):
else:
return False


def get_boolean_value(module, name):
state = 0
try:
Expand All @@ -97,6 +96,7 @@ def get_boolean_value(module, name):
else:
return False


# The following method implements what setsebool.c does to change
# a boolean and make it persist after reboot..
def semanage_boolean_value(module, name, state):
Expand Down Expand Up @@ -152,6 +152,7 @@ def semanage_boolean_value(module, name, state):
module.fail_json(msg="Failed to manage policy for boolean %s: %s" % (name, str(e)))
return True


def set_boolean_value(module, name, state):
rc = 0
value = 0
Expand All @@ -166,14 +167,15 @@ def set_boolean_value(module, name, state):
else:
return False


def main():
module = AnsibleModule(
argument_spec = dict(
name=dict(required=True),
persistent=dict(default='no', type='bool'),
state=dict(required=True, type='bool')
argument_spec=dict(
name=dict(type='str', required=True),
persistent=dict(type='bool', default=False),
state=dict(type='bool', required=True)
),
supports_check_mode=True
supports_check_mode=True,
)

if not HAVE_SELINUX:
Expand All @@ -188,8 +190,9 @@ def main():
name = module.params['name']
persistent = module.params['persistent']
state = module.params['state']
result = {}
result['name'] = name
result = dict(
name=name,
)

if hasattr(selinux, 'selinux_boolean_sub'):
# selinux_boolean_sub allows sites to rename a boolean and alias the old name
Expand Down
1 change: 0 additions & 1 deletion test/sanity/pep8/legacy-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ lib/ansible/modules/system/osx_defaults.py
lib/ansible/modules/system/pam_limits.py
lib/ansible/modules/system/puppet.py
lib/ansible/modules/system/runit.py
lib/ansible/modules/system/seboolean.py
lib/ansible/modules/system/seport.py
lib/ansible/modules/system/service.py
lib/ansible/modules/system/solaris_zone.py
Expand Down

0 comments on commit edc0ff4

Please sign in to comment.