role_chk_upgrades/tasks/main.yml

49 lines
1.5 KiB
YAML

---
###########################################################################
#
# This role will check for available package upgrades on the target host.
#
###########################################################################
#
# NOTE:
# The following variable(s) must be specified in the calling playbook (usually
# done by doing a 'gather_facts' action);
#
# {{ ansible_distribution }}
# {{ ansible_os_family }}
#
###########################################################################
# tasks file for chk_upgrades
- debug: msg="Checking for package updates"
############################################################
- name: Checked for updates (Debian based distros)
shell:
cmd: apt list --upgradable
register: dchkout
when: ansible_os_family == "Debian"
- name: Show output from update check (deb 1)
debug: msg={{ dchkout.stdout_lines }}
when: dchkout.stdout_lines is defined and ansible_os_family == "Debian"
- name: Show output from update check (deb 2)
debug: msg={{ dchkout }}
when: dchkout.stdout_lines is undefined and ansible_os_family == "Debian"
- name: Checked for updates (Arch based distros)
shell:
cmd: pacman -Qu
register: achkout
when: ansible_os_family == "Archlinux"
# 'pacman -Qu' returns a 1 when no packages require upgrade
# this line stops the role from failing with a 'non-zero result'
failed_when: "achkout.rc not in [ 0, 1 ]"
- name: Show output from update check (arch 1)
debug: msg={{ achkout.stdout_lines }}
when: achkout.stdout_lines is defined and ansible_os_family == "Archlinux"
# EOF