I am opening a playbook to update patches in centos, but first I need to validate that there are updated packages and in case the tasks are not stopped.
I am using the yum plugin to validate if there are updates but when trying to fail the task with a debug in case there are no updates it does not allow me to validate and always gives skyp.
Playbook.
---
- hosts: "{{ hosts}}"
become: true
tasks:
- name: check updates
yum:
list: updates
update_cache: true
register: salida
- name: show yum
debug:
msg: "{{ salida }}"
when: '"yumstate" in salida.results'
...
Output
TASK [Gathering Facts] *********************************************************************************************************************
ok: []
TASK [check updates] **********************************************************************************************************************
ok: []
TASK [show yum] ************************************************************************************************************
skipping: []
Output var.
"msg": [
{
"arch": "x86_64",
"envra": "0:",
"epoch": "0",
"name": "",
"release": "3770.el7",
"repo": "",
"version": "20.0.0",
"yumstate": "available"
},
{
"arch": "x86_64",
"envra": "0:",
"epoch": "0",
"name": "syslog-ng-premium-edition-compact",
"release": "1.rhel7",
"repo": "",
"version": "7.0.29",
"yumstate": "available"
}
]
}