Note
This module is part of the community.general collection (version 10.7.3).
You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.
To use it in a playbook, specify: community.general.sefcontext.
semanage fcontext command.The below requirements are needed on the host that executes this module.
Parameter | Comments |
|---|---|
ftype string | The file type that should have SELinux contexts applied. The following file type options are available:
Choices:
|
ignore_selinux_state boolean | Useful for scenarios (chrooted environment) that you cannot get the real SELinux state. Choices:
|
reload boolean | Reload SELinux policy after commit. Note that this does not apply SELinux file contexts to existing files. Choices:
|
selevel aliases: serange string | SELinux range for the specified Defaults to |
setype string | SELinux type for the specified |
seuser string | SELinux user for the specified Defaults to |
state string | Whether the SELinux file context must be Specifying Choices:
|
substitute aliases: equal string added in community.general 6.4.0 | |
target aliases: path string / required | Target path (expression). |
Attribute | Support | Description |
|---|---|---|
check_mode | Support: full | Can run in |
diff_mode | Support: full | Will return details on what has changed (or possibly needs changing in |
platform | Platform: linux | Target OS/families that can be operated against. |
Note
setype and substitute are mutually exclusive.state=present then one of setype or substitute is mandatory.restorecon manually for the existing files that require the new SELinux file contexts.- 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
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/general/sefcontext_module.html