Ansible系统角色——selinux
时间:2020-09-18 03:24:24
收藏:0
阅读:56
rhel-system-roles.selinux
此模块为为系统模块,可通过安装rhel-system-roles来获取。模块功能包括:
- 设置selinux模式(enforcing和permissive)
- 恢复文件默认上下文类型(restorecon)
- 设置获取上下文
- 管理登录以及端口
用法实例
设置/修改策略类型和模式
[root@localhost project2]# vim selinux.yml
---
- hosts: 192.168.190.134
vars:
selinux_policy: targeted
selinux_state: permissive
roles:
- role: roles/rhel-system-roles.selinux
这种方式只是临时修改(相当于手动执行setenforce,然后在未重启的情况下,disable模式并不会生效。所以需要把reboot加入到任务中
## reboot受控机并修改模式
[root@localhost project2]# vim selinux.yml
- hosts: 192.168.190.134
vars:
selinux_policy: targeted
selinux_state: disabled
tasks:- name: apply SElinux role
block:- include_role:
name: roles/rhel-system-roles.selinux
rescue: - name: check
fail:
when: not selinux_reboot_required - name: reboot
reboot: - name: changed
include_role:
name: roles/rhel-system-roles.selinux
- include_role:
- name: apply SElinux role
[root@localhost ~]# getenforce 查看被控机的工作模式
Disabled
```
##
评论(0)