mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 14:41:23 -07:00
sefcontext: PEP8 compliancy (#27742)
This commit is contained in:
parent
3c09f69765
commit
0342760f5b
2 changed files with 60 additions and 63 deletions
|
@ -12,60 +12,55 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
|
|||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: sefcontext
|
||||
short_description: Manages SELinux file context mapping definitions
|
||||
description:
|
||||
- Manages SELinux file context mapping definitions
|
||||
- Similar to the C(semanage fcontext) command
|
||||
version_added: "2.2"
|
||||
- Manages SELinux file context mapping definitions.
|
||||
- Similar to the C(semanage fcontext) command.
|
||||
version_added: '2.2'
|
||||
options:
|
||||
target:
|
||||
description:
|
||||
- Target path (expression).
|
||||
required: true
|
||||
default: null
|
||||
aliases: ['path']
|
||||
required: yes
|
||||
aliases: [ path ]
|
||||
ftype:
|
||||
description:
|
||||
- File type.
|
||||
required: false
|
||||
default: a
|
||||
setype:
|
||||
description:
|
||||
- SELinux type for the specified target.
|
||||
required: true
|
||||
default: null
|
||||
required: yes
|
||||
seuser:
|
||||
description:
|
||||
- SELinux user for the specified target.
|
||||
required: false
|
||||
default: null
|
||||
selevel:
|
||||
description:
|
||||
- SELinux range for the specified target.
|
||||
required: false
|
||||
default: null
|
||||
aliases: ['serange']
|
||||
aliases: [ serange ]
|
||||
state:
|
||||
description:
|
||||
- Desired boolean value.
|
||||
required: false
|
||||
choices: [ absent, present ]
|
||||
default: present
|
||||
choices: [ 'present', 'absent' ]
|
||||
reload:
|
||||
description:
|
||||
- Reload SELinux policy after commit.
|
||||
required: false
|
||||
default: yes
|
||||
type: bool
|
||||
default: 'yes'
|
||||
notes:
|
||||
- The changes are persistent across reboots
|
||||
requirements: [ 'libselinux-python', 'policycoreutils-python' ]
|
||||
author: Dag Wieers
|
||||
requirements:
|
||||
- libselinux-python
|
||||
- policycoreutils-python
|
||||
author:
|
||||
- Dag Wieers (@dagwieers)
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
EXAMPLES = r'''
|
||||
# Allow apache to modify files in /srv/git_repos
|
||||
- sefcontext:
|
||||
target: '/srv/git_repos(/.*)?'
|
||||
|
@ -73,7 +68,7 @@ EXAMPLES = '''
|
|||
state: present
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
RETURN = r'''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
@ -93,7 +88,7 @@ try:
|
|||
except ImportError:
|
||||
HAVE_SEOBJECT = False
|
||||
|
||||
### Add missing entries (backward compatible)
|
||||
# Add missing entries (backward compatible)
|
||||
if HAVE_SEOBJECT:
|
||||
seobject.file_types.update(dict(
|
||||
a=seobject.SEMANAGE_FCONTEXT_ALL,
|
||||
|
@ -106,7 +101,7 @@ if HAVE_SEOBJECT:
|
|||
s=seobject.SEMANAGE_FCONTEXT_SOCK,
|
||||
))
|
||||
|
||||
### Make backward compatible
|
||||
# Make backward compatible
|
||||
option_to_file_type_str = dict(
|
||||
a='all files',
|
||||
b='block device',
|
||||
|
@ -118,6 +113,7 @@ option_to_file_type_str = dict(
|
|||
s='socket file',
|
||||
)
|
||||
|
||||
|
||||
def semanage_fcontext_exists(sefcontext, target, ftype):
|
||||
''' Get the SELinux file context mapping definition from policy. Return None if it does not exist. '''
|
||||
|
||||
|
@ -129,6 +125,7 @@ def semanage_fcontext_exists(sefcontext, target, ftype):
|
|||
except KeyError:
|
||||
return None
|
||||
|
||||
|
||||
def semanage_fcontext_modify(module, result, target, ftype, setype, do_reload, serange, seuser, sestore=''):
|
||||
''' Add or modify SELinux file context mapping definition to the policy. '''
|
||||
|
||||
|
@ -181,6 +178,7 @@ def semanage_fcontext_modify(module, result, target, ftype, setype, do_reload, s
|
|||
|
||||
module.exit_json(changed=changed, seuser=seuser, serange=serange, **result)
|
||||
|
||||
|
||||
def semanage_fcontext_delete(module, result, target, ftype, do_reload, sestore=''):
|
||||
''' Delete SELinux file context mapping definition from the policy. '''
|
||||
|
||||
|
@ -217,12 +215,12 @@ def main():
|
|||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
target=dict(required=True, aliases=['path']),
|
||||
ftype = dict(required=False, choices=option_to_file_type_str.keys(), default='a'),
|
||||
setype = dict(required=True),
|
||||
seuser = dict(required=False, default=None),
|
||||
selevel = dict(required=False, default=None, aliases=['serange']),
|
||||
state = dict(required=False, choices=['present', 'absent'], default='present'),
|
||||
reload = dict(required=False, type='bool', default='yes'),
|
||||
ftype=dict(type='str', default='a', choices=option_to_file_type_str.keys()),
|
||||
setype=dict(type='str', required=True),
|
||||
seuser=dict(type='str'),
|
||||
selevel=dict(type='str', aliases=['serange']),
|
||||
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||
reload=dict(type='bool', default=True),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
|
|
@ -483,7 +483,6 @@ 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/sefcontext.py
|
||||
lib/ansible/modules/system/seport.py
|
||||
lib/ansible/modules/system/service.py
|
||||
lib/ansible/modules/system/solaris_zone.py
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue