From 2734895c482a0b4756cd37f1693e349711be73c9 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Tue, 18 Dec 2018 18:48:11 +0100 Subject: [PATCH] Do switch to apt if aptitude is not installed (#30738) Trying to use the apt module on a freshly install 16.04 Ubuntu VM with "ansible -m apt -a 'name=* state=latest' all" fail with this backtrace: Traceback (most recent call last): File \"/tmp/ansible_2inxygge/ansible_module_apt.py\", line 1055, in main() File \"/tmp/ansible_2inxygge/ansible_module_apt.py\", line 998, in main upgrade(module, 'yes', force_yes, p['default_release'], use_apt_get, dpkg_options) File \"/tmp/ansible_2inxygge/ansible_module_apt.py\", line 759, in upgrade apt_cmd_path = m.get_bin_path(apt_cmd, required=True) File \"/tmp/ansible_2inxygge/ansible_modlib.zip/ansible/module_utils/basic.py\", line 2182, in get_bin_path File \"/usr/lib/python3.5/posixpath.py\", line 89, in join genericpath._check_arg_types('join', a, *p) File \"/usr/lib/python3.5/genericpath.py\", line 143, in _check_arg_types (funcname, s.__class__.__name__)) from None TypeError: join() argument must be str or bytes, not 'NoneType' It seems that since aptitude is not installed on Xenial, so APTITUDE_CMD is None and we later hit the bug in the upgrade function since it assume APTITUDE_CMD is set. --- lib/ansible/modules/packaging/os/apt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/packaging/os/apt.py b/lib/ansible/modules/packaging/os/apt.py index ee76ec5331..9c84d041b2 100644 --- a/lib/ansible/modules/packaging/os/apt.py +++ b/lib/ansible/modules/packaging/os/apt.py @@ -1056,8 +1056,8 @@ def main(): use_apt_get = p['force_apt_get'] - if not use_apt_get and not APTITUDE_CMD and p.get('upgrade', None) in ['full', 'safe', 'yes']: - module.warn("Could not find aptitude. Using apt-get instead.") + if not use_apt_get and not APTITUDE_CMD: + module.warn("Could not find aptitude. Using apt-get instead") use_apt_get = True updated_cache = False