From 90f5e1925e23fa15983983d329db9bd6c4d46c5d Mon Sep 17 00:00:00 2001 From: Justin Lecher Date: Fri, 9 Jan 2015 16:07:42 +0100 Subject: [PATCH] Allow disabling of autorefresh for zypper repositories In case of release repositories or other special cases you might not need the autorefreshing of the repos. This patch adds a configure option instead of hard enabling this. Signed-off-by: Justin Lecher --- .../extras/packaging/os/zypper_repository.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/extras/packaging/os/zypper_repository.py b/lib/ansible/modules/extras/packaging/os/zypper_repository.py index 5e41683734..44a0ed6029 100644 --- a/lib/ansible/modules/extras/packaging/os/zypper_repository.py +++ b/lib/ansible/modules/extras/packaging/os/zypper_repository.py @@ -2,6 +2,7 @@ # encoding: utf-8 # (c) 2013, Matthias Vogelgesang +# (c) 2014, Justin Lecher # # This file is part of Ansible # @@ -58,6 +59,13 @@ options: default: "no" choices: [ "yes", "no" ] aliases: [] + refresh: + description: + - Enable autorefresh of the repository. + required: false + default: "no" + choices: [ "yes", "no" ] + aliases: [] notes: [] requirements: [ zypper ] ''' @@ -145,11 +153,11 @@ def repo_exists(module, old_zypper, **kwargs): return False -def add_repo(module, repo, alias, description, disable_gpg_check, old_zypper): +def add_repo(module, repo, alias, description, disable_gpg_check, old_zypper, refresh): if old_zypper: cmd = ['/usr/bin/zypper', 'sa'] else: - cmd = ['/usr/bin/zypper', 'ar', '--check', '--refresh'] + cmd = ['/usr/bin/zypper', 'ar', '--check'] if repo.startswith("file:/") and old_zypper: cmd.extend(['-t', 'Plaindir']) @@ -162,6 +170,9 @@ def add_repo(module, repo, alias, description, disable_gpg_check, old_zypper): if disable_gpg_check and not old_zypper: cmd.append('--no-gpgcheck') + if refresh: + cmd.append('--refresh') + cmd.append(repo) if not repo.endswith('.repo'): @@ -216,6 +227,7 @@ def main(): state=dict(choices=['present', 'absent'], default='present'), description=dict(required=False), disable_gpg_check = dict(required=False, default='no', type='bool'), + refresh = dict(required=False, default='yes', type='bool'), ), supports_check_mode=False, ) @@ -225,6 +237,7 @@ def main(): name = module.params['name'] description = module.params['description'] disable_gpg_check = module.params['disable_gpg_check'] + refresh = module.params['refresh'] def exit_unchanged(): module.exit_json(changed=False, repo=repo, state=state, name=name) @@ -260,7 +273,7 @@ def main(): if exists: exit_unchanged() - changed = add_repo(module, repo, name, description, disable_gpg_check, old_zypper) + changed = add_repo(module, repo, name, description, disable_gpg_check, old_zypper, refresh) elif state == 'absent': if not exists: exit_unchanged()