From 53d06b932aca8412f091e35f67512b085d4061c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Wed, 18 Sep 2013 11:47:39 +0200 Subject: [PATCH 1/2] apt_repository: fix update cache after state=changed. Closes GH-4136 --- packaging/apt_repository | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packaging/apt_repository b/packaging/apt_repository index a61a93b5864..5ec6bd49025 100644 --- a/packaging/apt_repository +++ b/packaging/apt_repository @@ -69,6 +69,7 @@ import re import tempfile try: + import apt import apt_pkg import aptsources.distro distro = aptsources.distro.get_distro() @@ -365,6 +366,8 @@ def main(): if not module.check_mode and changed: try: sourceslist.save(module) + cache = apt.Cache() + cache.update() except OSError as err: module.fail_json(msg=unicode(err)) From cb9308a9983eb3ecfb5c04a6a3b64839f8af6b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Wed, 18 Sep 2013 19:14:08 +0200 Subject: [PATCH 2/2] apt_repository: added option update_cache. The default behavior is to update_cache if changed. If you add more then one repo, you may not want to update cache for every repo separately. So you can now disable update_cache with this new option e.g. update_cache=no Updating cache can also be handled using the apt module. --- packaging/apt_repository | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packaging/apt_repository b/packaging/apt_repository index 5ec6bd49025..e811ee0cbb0 100644 --- a/packaging/apt_repository +++ b/packaging/apt_repository @@ -42,6 +42,12 @@ options: default: "present" description: - A source string state. + update_cache: + description: + - Run the equivalent of C(apt-get update) if has changed. + required: false + default: "yes" + choices: [ "yes", "no" ] author: Alexander Saltanov version_added: "0.7" requirements: [ python-apt, python-pycurl ] @@ -329,6 +335,7 @@ def main(): argument_spec=dict( repo=dict(required=True), state=dict(choices=['present', 'absent'], default='present'), + update_cache = dict(aliases=['update-cache'], type='bool'), ), supports_check_mode=True, ) @@ -341,6 +348,7 @@ def main(): repo = module.params['repo'] state = module.params['state'] + update_cache = module.params['update_cache'] sourceslist = None if isinstance(distro, aptsources.distro.DebianDistribution): @@ -366,8 +374,9 @@ def main(): if not module.check_mode and changed: try: sourceslist.save(module) - cache = apt.Cache() - cache.update() + if update_cache: + cache = apt.Cache() + cache.update() except OSError as err: module.fail_json(msg=unicode(err))