community.general.serestorecon module – Restore SELinux file contexts
Note
This module is part of the community.general collection (version 14.0.0).
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.serestorecon.
New in community.general 13.5.0
Synopsis
Restores SELinux file contexts to the values defined by the active SELinux policy.
Similar to the
restoreconcommand.
Requirements
The below requirements are needed on the host that executes this module.
SELinux Python bindings (
libselinux-pythonor distribution equivalent)
Parameters
Parameter |
Comments |
|---|---|
Controls which components of the SELinux context are restored.
Choices:
|
|
Whether recursive processing can include paths on filesystems other than the filesystem containing When This option only has an effect when Choices:
|
|
Path whose SELinux file context should be restored. |
|
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full |
Can run in |
|
Support: full |
Returns details on what has changed (or possibly needs changing in |
Examples
- name: Restore the SELinux type for a file
community.general.serestorecon:
path: /etc/httpd/conf/httpd.conf
- name: Recursively restore SELinux types
community.general.serestorecon:
path: /var/www/html
recurse: true
- name: Restore contexts while excluding a directory
community.general.serestorecon:
path: /var/www/html
recurse: true
exclude_paths:
- /var/www/html/cache
- name: Do not process paths on other filesystems
community.general.serestorecon:
path: /srv
recurse: true
cross_filesystems: false
- name: Restore the SELinux user, role, and type
community.general.serestorecon:
path: /var/www/html
recurse: true
context: user_role
- name: Restore the complete policy-defined SELinux context
community.general.serestorecon:
path: /var/www/html
recurse: true
context: full
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Paths whose SELinux contexts were restored. Returned: success |
|
Path whose SELinux context required restoration. Returned: success Sample: |
|
SELinux context before restoration. Returned: success Sample: |
|
SELinux context read back after restoration. Returned: success Sample: |