community.general.sefcontext 模块 – 管理 SELinux 文件上下文映射定义
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible
软件包,则可能已安装此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install community.general
。您需要其他要求才能使用此模块,有关详细信息,请参见 要求。
要在 playbook 中使用它,请指定: community.general.sefcontext
。
概要
管理 SELinux 文件上下文映射定义。
类似于
semanage fcontext
命令。
要求
执行此模块的主机需要以下要求。
libselinux-python
policycoreutils-python
参数
参数 |
注释 |
---|---|
应应用 SELinux 上下文的文文件类型。 可以使用以下文件类型选项
选项
|
|
对于无法获取真实 SELinux 状态的场景(chroot 环境)非常有用。 选项
|
|
提交后重新加载 SELinux 策略。 请注意,这不会将 SELinux 文件上下文应用于现有文件。 选项
|
|
指定 对于新的文件上下文默认为 |
|
指定 |
|
指定 对于新的文件上下文默认为 |
|
SELinux 文件上下文必须为 在不使用 选项
|
|
目标路径(表达式)。 |
属性
属性 |
支持 |
描述 |
---|---|---|
支持:完全支持 |
可以在 |
|
支持:完全支持 |
在差异模式下,将返回有关已更改内容(或在 |
|
平台: Linux |
可以对其进行操作的目标操作系统/系列。 |
备注
注意
这些更改在重启后仍然有效。
setype
和substitute
是互斥的。如果
state=present
,则setype
或substitute
中的一个是必填的。community.general.sefcontext 模块不会将现有文件修改为新的 SELinux 上下文,因此建议先创建 SELinux 文件上下文,然后再创建文件,或者手动为需要新 SELinux 文件上下文的现有文件运行
restorecon
。不将 SELinux fcontext 应用于现有文件是一个深思熟虑的决定,因为不清楚报告的更改将带来什么影响,而且不能保证应用 SELinux fcontext 不会拾取其他无关的先前更改。
示例
- name: Allow apache to modify files in /srv/git_repos
community.general.sefcontext:
target: '/srv/git_repos(/.*)?'
setype: httpd_sys_rw_content_t
state: present
- name: Substitute file contexts for path /srv/containers with /var/lib/containers
community.general.sefcontext:
target: /srv/containers
substitute: /var/lib/containers
state: present
- name: Delete file context path substitution for /srv/containers
community.general.sefcontext:
target: /srv/containers
substitute: /var/lib/containers
state: absent
- name: Delete any file context mappings for path /srv/git
community.general.sefcontext:
target: /srv/git
state: absent
- name: Apply new SELinux file context to filesystem
ansible.builtin.command: restorecon -irv /srv/git_repos