I am working on a playbook that uses yum. When yum does an update of all installed packages I want to do a conditional shutdown -r. What condition do I check from the yum task succeeding?
Mike
I am working on a playbook that uses yum. When yum does an update of all installed packages I want to do a conditional shutdown -r. What condition do I check from the yum task succeeding?
Mike
1) If you want to reboot on any change just notify a handler
- yum:
...
notify: reboot
Note: "update_cache" makes "yum" report "changed" even when no package have
been changed (installed/upgraded/downgraded); hence "update_cache" in a
separate task.
2) If you want to reboot on a particular combination of changes register
"yum_result" and make your choice.
- yum:
...
register: yum_result
- command: shutdown -r
when: <condition based on yum_result>
Note: See details in
How to access information in ansible yum list result?
https://stackoverflow.com/questions/49272469/how-to-access-information-in-ansible-yum-list-result
Cheers,
-vlado
Not all package updates require a reboot.
You can make this more robust by installing yum-utils, run /sbin/needs-restarting, and decide based on what that returns.
Example:
https://luktom.net/en/e1497-how-to-update-centos-rhel-using-ansible
On Debian based distros you’d check for the presence of /var/run/reboot-required.
Dick
Vladimir Botka,
I certifie , You are the best Vladimir !!
Very the best
Regards,