-
Notifications
You must be signed in to change notification settings - Fork 50
/
selinux-playbook.yml
89 lines (84 loc) · 2.54 KB
/
selinux-playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
- name: Manage SELinux policy example
hosts: all
vars:
# Use "targeted" SELinux policy type
selinux_policy: targeted
# Set "enforcing" mode
selinux_state: enforcing
# Switch some SELinux booleans
selinux_booleans:
# Set the 'samba_enable_home_dirs' boolean to 'on' in the current
# session only
- name: samba_enable_home_dirs
state: true
# Set the 'ssh_sysadm_login' boolean to 'on' permanently
- name: ssh_sysadm_login
state: true
persistent: true
# Map '/tmp/test_dir' and its subdirectories to the 'user_home_dir_t'
# SELinux file type
selinux_fcontexts:
- target: '/tmp/test_dir(/.*)?'
setype: user_home_dir_t
ftype: d
state: present
# Restore SELinux file contexts in '/tmp/test_dir'
selinux_restore_dirs:
- /tmp/test_dir
# Map tcp port 22100 to the 'ssh_port_t' SELinux port type
selinux_ports:
- ports: 22100
proto: tcp
setype: ssh_port_t
state: present
# Map the 'sar-user' Linux user to the 'staff_u' SELinux user
selinux_logins:
- login: sar-user
seuser: staff_u
serange: s0-s0:c0.c1023
state: present
# Manage modules
selinux_modules:
# Install the 'localpolicy.cil' with priority 300
- path: localpolicy.cil
priority: 300
state: enabled
# Disable the 'unconfineduser' module with priority 100
- name: unconfineduser
priority: 100
state: disabled
# Remove the 'temporarypolicy' module with priority 400
- name: temporarypolicy
priority: 400
state: absent
tasks:
- name: Creates directory
file:
path: /tmp/test_dir
state: directory
mode: "0755"
- name: Add a Linux System Roles SELinux User
user:
comment: Linux System Roles SELinux User
name: sar-user
- name: Execute the role and reboot in a rescue block
block:
- name: Include selinux role
include_role:
name: linux-system-roles.selinux
rescue:
- name: >-
Fail if failed for a different reason than selinux_reboot_required
fail:
msg: "role failed"
when: not selinux_reboot_required
- name: Restart managed host
reboot:
- name: Wait for managed host to come back
wait_for_connection:
delay: 10
timeout: 300
- name: Reapply the role
include_role:
name: linux-system-roles.selinux