From 6fdad493092147de2873008c39a0670ba2a0d036 Mon Sep 17 00:00:00 2001 From: Robin Roth Date: Sat, 9 Jul 2016 11:38:12 +0200 Subject: [PATCH] allow overwrite_multiple with more than 2 repos (#2481) 2.1 introduces overwrite_multiple, which can overwrite more than one exisiting repo (with matching alias or URL). Allow more than 2 repos to be overwritten, since openSuSE allow more than one repo with the same URL if the alias is different. --- .../extras/packaging/os/zypper_repository.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/extras/packaging/os/zypper_repository.py b/lib/ansible/modules/extras/packaging/os/zypper_repository.py index 0e4e805856d..54a641c7b5f 100644 --- a/lib/ansible/modules/extras/packaging/os/zypper_repository.py +++ b/lib/ansible/modules/extras/packaging/os/zypper_repository.py @@ -157,13 +157,15 @@ def repo_exists(module, repodata, overwrite_multiple): # Found an existing repo, look for changes has_changes = _repo_changes(repos[0], repodata) return (True, has_changes, repos) - elif len(repos) == 2 and overwrite_multiple: - # Found two repos and want to overwrite_multiple - return (True, True, repos) - else: - # either more than 2 repos (shouldn't happen) - # or overwrite_multiple is not active - module.fail_json(msg='More than one repo matched "%s": "%s"' % (name, repos)) + elif len(repos) >= 2: + if overwrite_multiple: + # Found two repos and want to overwrite_multiple + return (True, True, repos) + else: + errmsg = 'More than one repo matched "%s": "%s".' % (name, repos) + errmsg += ' Use overwrite_multiple to allow more than one repo to be overwritten' + module.fail_json(msg=errmsg) + def modify_repo(module, repodata, old_repos): repo = repodata['url']