|
|
@ -1,17 +1,15 @@
|
|
|
|
#!/usr/bin/python
|
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
|
|
|
|
# (c) 2016, Dag Wieers <dag@wieers.com>
|
|
|
|
# Copyright: (c) 2016, Dag Wieers (@dagwieers) <dag@wieers.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# 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
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|
|
|
'status': ['preview'],
|
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = r'''
|
|
|
|
DOCUMENTATION = r'''
|
|
|
|
---
|
|
|
|
---
|
|
|
|
module: sefcontext
|
|
|
|
module: sefcontext
|
|
|
@ -24,11 +22,22 @@ options:
|
|
|
|
target:
|
|
|
|
target:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Target path (expression).
|
|
|
|
- Target path (expression).
|
|
|
|
|
|
|
|
type: str
|
|
|
|
required: yes
|
|
|
|
required: yes
|
|
|
|
aliases: [ path ]
|
|
|
|
aliases: [ path ]
|
|
|
|
ftype:
|
|
|
|
ftype:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- File type.
|
|
|
|
- File type.
|
|
|
|
|
|
|
|
- The following file type options can be passed;
|
|
|
|
|
|
|
|
C(a) for all files,
|
|
|
|
|
|
|
|
C(b) for block devices,
|
|
|
|
|
|
|
|
C(c) for character devices,
|
|
|
|
|
|
|
|
C(d) for directories,
|
|
|
|
|
|
|
|
C(f) for regular files,
|
|
|
|
|
|
|
|
C(l) for symbolic links,
|
|
|
|
|
|
|
|
C(p) for named pipes,
|
|
|
|
|
|
|
|
C(s) for socket files.
|
|
|
|
|
|
|
|
type: str
|
|
|
|
default: a
|
|
|
|
default: a
|
|
|
|
setype:
|
|
|
|
setype:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
@ -37,26 +46,34 @@ options:
|
|
|
|
seuser:
|
|
|
|
seuser:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- SELinux user for the specified target.
|
|
|
|
- SELinux user for the specified target.
|
|
|
|
|
|
|
|
type: str
|
|
|
|
selevel:
|
|
|
|
selevel:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- SELinux range for the specified target.
|
|
|
|
- SELinux range for the specified target.
|
|
|
|
|
|
|
|
type: str
|
|
|
|
aliases: [ serange ]
|
|
|
|
aliases: [ serange ]
|
|
|
|
state:
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Desired boolean value.
|
|
|
|
- Whether the SELinux file context must be C(absent) or C(present).
|
|
|
|
|
|
|
|
type: str
|
|
|
|
choices: [ absent, present ]
|
|
|
|
choices: [ absent, present ]
|
|
|
|
default: present
|
|
|
|
default: present
|
|
|
|
reload:
|
|
|
|
reload:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Reload SELinux policy after commit.
|
|
|
|
- Reload SELinux policy after commit.
|
|
|
|
|
|
|
|
- Note that this does not apply SELinux file contexts to existing files.
|
|
|
|
type: bool
|
|
|
|
type: bool
|
|
|
|
default: 'yes'
|
|
|
|
default: 'yes'
|
|
|
|
notes:
|
|
|
|
notes:
|
|
|
|
- The changes are persistent across reboots
|
|
|
|
- The changes are persistent across reboots.
|
|
|
|
- The M(sefcontext) module does not modify existing files to the new
|
|
|
|
- The M(sefcontext) module does not modify existing files to the new
|
|
|
|
SELinux context(s), so it is advisable to first create the SELinux
|
|
|
|
SELinux context(s), so it is advisable to first create the SELinux
|
|
|
|
file contexts before creating files, or run C(restorecon) manually
|
|
|
|
file contexts before creating files, or run C(restorecon) manually
|
|
|
|
for the existing files that require the new SELinux file contexts.
|
|
|
|
for the existing files that require the new SELinux file contexts.
|
|
|
|
|
|
|
|
- Not applying SELinux fcontexts to existing files is a deliberate
|
|
|
|
|
|
|
|
decision as it would be unclear what reported changes would entail
|
|
|
|
|
|
|
|
to, and there's no guarantee that applying SELinux fcontext does
|
|
|
|
|
|
|
|
not pick up other unrelated prior changes.
|
|
|
|
requirements:
|
|
|
|
requirements:
|
|
|
|
- libselinux-python
|
|
|
|
- libselinux-python
|
|
|
|
- policycoreutils-python
|
|
|
|
- policycoreutils-python
|
|
|
@ -65,11 +82,14 @@ author:
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = r'''
|
|
|
|
EXAMPLES = r'''
|
|
|
|
# Allow apache to modify files in /srv/git_repos
|
|
|
|
- name: Allow apache to modify files in /srv/git_repos
|
|
|
|
- sefcontext:
|
|
|
|
sefcontext:
|
|
|
|
target: '/srv/git_repos(/.*)?'
|
|
|
|
target: '/srv/git_repos(/.*)?'
|
|
|
|
setype: httpd_git_rw_content_t
|
|
|
|
setype: httpd_git_rw_content_t
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Apply new SELinux file context to filesystem
|
|
|
|
|
|
|
|
command: restorecon -irv /srv/git_repos
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = r'''
|
|
|
|
RETURN = r'''
|
|
|
|