I was writing an internal role that handles all things SELinux which can be included in playbooks just like any other role. However, I found out that when templating /etc/selinux/config using ansible and jinja2, you will have to use
SELINUX={{ selinux_state }}
instead of
SELINUX="{{ selinux_state }}"
since this might result in a system unable to log in or start any login manager due to not being able to load the correct context. There's the gotcha but how to fix it?
Reboot the machine into emergency mode.
--> Press 'e' in the grub menu
--> add 'rd.break' to the boot_cmdline like shown in the picture and press 'ctrl' + 'x' to boot
From here on out, remount the /sysroot directory as read-write
switch_root:/# mount -o remount,rw /sysroot
chroot into your installation
switch_root:/# chroot /sysroot
fix the /etc/selinux/config and relabel everything (just to ensure everything is going to be labeled correctly).
sh-4.2# vi /etc/selinux/config
sh-4.2# touch /.autorelabel
sh-4.2# exit
Reboot into the machine into the normal target
switch_root:/# reboot
The relabeling might take a while depending on the size of the filesystem.
Feel free to comment and / or suggest a topic.
Comments
Post a Comment