-
-
Save seriald/79a3a2451b29cf5e86fbe3b9654d9929 to your computer and use it in GitHub Desktop.
Ansible playbook to update and upgrade Debian hosts
This file contains 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: all | |
sudo: yes | |
tasks: | |
- name: Update packages list | |
apt: update_cache=yes | |
when: ansible_os_family == 'Debian' | |
- name: List packages to upgrade (1/2) | |
shell: aptitude -q -F%p --disable-columns search "~U" | |
register: updates | |
changed_when: False | |
when: ansible_os_family == 'Debian' | |
- name: List packages to upgrade (2/2) | |
debug: msg="{{ updates.stdout_lines | count }} packages to upgrade ({{ updates.stdout_lines | join(', ') }})" | |
when: (ansible_os_family == 'Debian' and updates.stdout_lines) | |
- name: Upgrade packages | |
apt: upgrade=safe | |
when: ansible_os_family == 'Debian' | |
- name: Check what the new version is | |
shell: lsb_release -r | awk '{print $2}' | |
changed_when: False | |
register: new_release | |
- name: Notify distribution version upgrade | |
debug: msg="Debian has been upgraded from {{ ansible_lsb.release }} to {{ new_release.stdout }}" | |
when: ansible_lsb.release != new_release.stdout | |
- name: List services to restart (1/2) | |
shell: checkrestart | grep ^service | awk '{print $2}' | |
register: services | |
changed_when: False | |
when: ansible_os_family == 'Debian' | |
- name: List services to restart (2/2) | |
debug: msg="{{ services.stdout_lines | count }} services to restart ({{ services.stdout_lines | join (', ') }})" | |
when: (ansible_os_family == 'Debian' and services.stdout_lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with --ask-sudo-pass