From d6e711b1dedf5908bdae25d3e9496a241d0e49d4 Mon Sep 17 00:00:00 2001 From: Robin Roth Date: Mon, 14 May 2018 14:51:10 +0200 Subject: [PATCH] Allow empty list of names in pip module (#38789) pip 10 gives exit code 1 for empty argument lists (pip < 10 gave exit 0) see also https://github.com/pypa/pip/pull/4210 To still allow playbooks to pass when giving empty lists, don't call pip in that case, but show a warning. --- lib/ansible/modules/packaging/language/pip.py | 8 ++++++-- test/integration/targets/pip/tasks/pip.yml | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/packaging/language/pip.py b/lib/ansible/modules/packaging/language/pip.py index 83ee128c29..19665e8f13 100644 --- a/lib/ansible/modules/packaging/language/pip.py +++ b/lib/ansible/modules/packaging/language/pip.py @@ -496,9 +496,13 @@ def main(): if name: for pkg in name: cmd += ' %s' % _get_full_name(pkg, version) + elif requirements: + cmd += ' -r %s' % requirements else: - if requirements: - cmd += ' -r %s' % requirements + module.exit_json( + changed=False, + warnings=["No valid name or requirements file found."], + ) if module.check_mode: if extra_args or requirements or state == 'latest' or not name: diff --git a/test/integration/targets/pip/tasks/pip.yml b/test/integration/targets/pip/tasks/pip.yml index 25c70bf6b3..be46a28ad6 100644 --- a/test/integration/targets/pip/tasks/pip.yml +++ b/test/integration/targets/pip/tasks/pip.yml @@ -208,3 +208,14 @@ assert: that: - "venv_chdir.changed" + +# ansible#38785 +- name: allow empty list of packages + pip: + name: [] + register: pip_install_empty + +- name: ensure empty install is successful + assert: + that: + - not pip_install_empty.changed