From 26d9de6f3e08c9df1f7e8f8a78eac13666252f02 Mon Sep 17 00:00:00 2001 From: Julien Vey Date: Mon, 19 Mar 2018 15:16:43 +0100 Subject: [PATCH] apt_repository: check attribute repo for None value (#36944) --- .../modules/packaging/os/apt_repository.py | 3 +++ .../targets/apt_repository/tasks/apt.yml | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/ansible/modules/packaging/os/apt_repository.py b/lib/ansible/modules/packaging/os/apt_repository.py index 044096be33..851cf8c9ce 100644 --- a/lib/ansible/modules/packaging/os/apt_repository.py +++ b/lib/ansible/modules/packaging/os/apt_repository.py @@ -503,6 +503,9 @@ def main(): else: module.fail_json(msg='%s is not installed, and install_python_apt is False' % PYTHON_APT) + if not repo: + module.fail_json(msg='Please set argument \'repo\' to a non-empty value') + if isinstance(distro, aptsources_distro.Distribution): sourceslist = UbuntuSourcesList(module, add_ppa_signing_keys_callback=get_add_ppa_signing_key_callback(module)) else: diff --git a/test/integration/targets/apt_repository/tasks/apt.yml b/test/integration/targets/apt_repository/tasks/apt.yml index add2997ab5..612a7f270d 100644 --- a/test/integration/targets/apt_repository/tasks/apt.yml +++ b/test/integration/targets/apt_repository/tasks/apt.yml @@ -199,6 +199,28 @@ - name: 'ensure ppa key is absent (expect: pass)' apt_key: id='{{test_ppa_key}}' state=absent +- name: Test apt_repository with a null value for repo + apt_repository: + repo: + register: result + ignore_errors: yes + +- assert: + that: + - result is failed + - result.msg == 'Please set argument \'repo\' to a non-empty value' + +- name: Test apt_repository with an empty value for repo + apt_repository: + repo: "" + register: result + ignore_errors: yes + +- assert: + that: + - result is failed + - result.msg == 'Please set argument \'repo\' to a non-empty value' + # # TEARDOWN #