I task a task that disables selinux on a managed host before performing an installation.
However ansible returning a warning informing that reboot is needed for setting to take effect:
TASK [Gathering Facts] ********************************************************************************************
Thursday 16 December 2021 09:07:08 -0800 (0:00:00.110) 0:00:00.110 *****
ok: [vng.cs.east.com]
TASK [disable seLinux] ********************************************************************************************
Thursday 16 December 2021 09:07:35 -0800 (0:00:27.138) 0:00:27.249 *****
[WARNING]: SELinux state change will take effect next reboot
changed: [vng.cs.east.com]
PLAY RECAP ********************************************************************************************************
vng.cs.east.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
I would like to include a reboot task in my play, to conditionally reboot the server if this warning is issued. I’m not sure how to capture the warning for use in a conditional statement for the reboot task.
Is this possible?
>Solution :
If you are disable SELinux (… which is not recommended at all and should by avoided in any case) via the selinux_module
- name: Disable SELinux
ansible.posix.selinux:
state: disabled
you may just check the Return Values and perform further tasks like
- name: Reboot if required
reboot:
reboot_timeout: 300
when: reboot_required