Issue
I'm getting an error when running the following Ansible task:
- 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'
Error:
TASK [List packages to upgrade (1/2)] ********************************************************************************************************************************
fatal: [php7e]: FAILED! => {"changed": false, "cmd": "aptitude -q -F%p --disable-columns search \"~U\"", "delta": "0:00:00.828791", "end": "2021-06-23 10:31:26.849961", "msg": "non-zero return code", "rc": 1, "start": "2021-06-23 10:31:26.021170", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
Noticed on another server, I don't get this error. The server that doesn't have an issue has aptitude 0.7.4 and the one with the errors has aptitude 0.8.10.
Solution
obviously aptitude search
returns with an exit-code of 1
if no packages match the search term (in your case: if there are no upgradable packages)
as per the changelog:
aptitude (0.7.6-1) unstable; urgency=low [...] * [cmdline] "search" now exits with non-zero on errors or empty results (Closes: #497299)
so: the observed behaviour is correct and expected. you must update your ansible task accordingly.
Answered By - umläute Answer Checked By - Marilyn (WPSolving Volunteer)