Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ansible reboot server if task warns

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading