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