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 <jlec@gentoo.org>
This commit is contained in:
Justin Lecher 2015-01-09 16:07:42 +01:00 committed by Matt Clay
parent 0df24a61c5
commit 90f5e1925e

View file

@ -2,6 +2,7 @@
# encoding: utf-8 # encoding: utf-8
# (c) 2013, Matthias Vogelgesang <matthias.vogelgesang@gmail.com> # (c) 2013, Matthias Vogelgesang <matthias.vogelgesang@gmail.com>
# (c) 2014, Justin Lecher <jlec@gentoo.org>
# #
# This file is part of Ansible # This file is part of Ansible
# #
@ -58,6 +59,13 @@ options:
default: "no" default: "no"
choices: [ "yes", "no" ] choices: [ "yes", "no" ]
aliases: [] aliases: []
refresh:
description:
- Enable autorefresh of the repository.
required: false
default: "no"
choices: [ "yes", "no" ]
aliases: []
notes: [] notes: []
requirements: [ zypper ] requirements: [ zypper ]
''' '''
@ -145,11 +153,11 @@ def repo_exists(module, old_zypper, **kwargs):
return False 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: if old_zypper:
cmd = ['/usr/bin/zypper', 'sa'] cmd = ['/usr/bin/zypper', 'sa']
else: else:
cmd = ['/usr/bin/zypper', 'ar', '--check', '--refresh'] cmd = ['/usr/bin/zypper', 'ar', '--check']
if repo.startswith("file:/") and old_zypper: if repo.startswith("file:/") and old_zypper:
cmd.extend(['-t', 'Plaindir']) 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: if disable_gpg_check and not old_zypper:
cmd.append('--no-gpgcheck') cmd.append('--no-gpgcheck')
if refresh:
cmd.append('--refresh')
cmd.append(repo) cmd.append(repo)
if not repo.endswith('.repo'): if not repo.endswith('.repo'):
@ -216,6 +227,7 @@ def main():
state=dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent'], default='present'),
description=dict(required=False), description=dict(required=False),
disable_gpg_check = dict(required=False, default='no', type='bool'), disable_gpg_check = dict(required=False, default='no', type='bool'),
refresh = dict(required=False, default='yes', type='bool'),
), ),
supports_check_mode=False, supports_check_mode=False,
) )
@ -225,6 +237,7 @@ def main():
name = module.params['name'] name = module.params['name']
description = module.params['description'] description = module.params['description']
disable_gpg_check = module.params['disable_gpg_check'] disable_gpg_check = module.params['disable_gpg_check']
refresh = module.params['refresh']
def exit_unchanged(): def exit_unchanged():
module.exit_json(changed=False, repo=repo, state=state, name=name) module.exit_json(changed=False, repo=repo, state=state, name=name)
@ -260,7 +273,7 @@ def main():
if exists: if exists:
exit_unchanged() 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': elif state == 'absent':
if not exists: if not exists:
exit_unchanged() exit_unchanged()