Created
November 3, 2024 09:15
-
-
Save stylersnico/4fe50887ce9ed120a98b834443823f09 to your computer and use it in GitHub Desktop.
Update and reboot Debian host if needed with ansible and needrestart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - hosts: debian | |
| become: yes | |
| become_method: sudo | |
| tasks: | |
| - name: updates a server | |
| apt: update_cache=yes | |
| - name: upgrade a server | |
| apt: upgrade=dist dpkg_options='force-confold,force-confdef' | |
| - name: Check if a reboot is required | |
| shell: needrestart -k -p > /dev/null; echo $? | |
| register: reboot | |
| - name: Reboot the services | |
| shell: needrestart -ra -l | |
| when: reboot.stdout == "0" | |
| - name: Reboot the server using reboot | |
| command: /sbin/reboot | |
| async: 1 | |
| poll: 0 | |
| when: reboot.stdout == "2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment