From 4976429e423b5de283885637491b168c097a8ee9 Mon Sep 17 00:00:00 2001 From: Robin Roth Date: Wed, 11 Jan 2017 19:47:16 +0100 Subject: [PATCH] Zypper: Fix update_cache in checkmode (#20143) Fixes #20139 Refresh does not support dry-run, so don't run it in check mode. Also add a test for this case. --- lib/ansible/modules/packaging/os/zypper.py | 4 ++-- .../targets/zypper/tasks/zypper.yml | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/packaging/os/zypper.py b/lib/ansible/modules/packaging/os/zypper.py index e219de50827..8628d52c270 100644 --- a/lib/ansible/modules/packaging/os/zypper.py +++ b/lib/ansible/modules/packaging/os/zypper.py @@ -95,7 +95,7 @@ options: update_cache: version_added: "2.2" description: - - Run the equivalent of C(zypper refresh) before the operation. + - Run the equivalent of C(zypper refresh) before the operation. Disabled in check mode. required: false default: "no" choices: [ "yes", "no" ] @@ -449,7 +449,7 @@ def main(): name = filter(None, name) # Refresh repositories - if update_cache: + if update_cache and not module.check_mode: retvals = repo_refresh(module) if retvals['rc'] != 0: diff --git a/test/integration/targets/zypper/tasks/zypper.yml b/test/integration/targets/zypper/tasks/zypper.yml index 4fe05f0125e..c79c5e6cf6a 100644 --- a/test/integration/targets/zypper/tasks/zypper.yml +++ b/test/integration/targets/zypper/tasks/zypper.yml @@ -334,3 +334,27 @@ - zypperin1|changed - not zypperin2|changed when: ansible_distribution == 'openSUSE Leap' and ansible_distribution_version == '42.1' + + +# check for https://github.com/ansible/ansible/issues/20139 +- name: run updatecache + zypper: + name: hello + state: present + update_cache: True + register: zypper_result_update_cache + +- name: run updatecache in check mode + zypper: + name: hello + state: present + update_cache: True + check_mode: True + register: zypper_result_update_cache_check + + +- assert: + that: + - zypper_result_update_cache|success + - zypper_result_update_cache_check|success + - not zypper_result_update_cache_check|changed