Merge branch 'fix/apt_repository_update_cache' of https://github.com/resmo/ansible into resmo-fix/apt_repository_update_cache

This commit is contained in:
James Cammarata 2013-09-18 12:40:39 -05:00
commit bb36429fa2

View file

@ -42,6 +42,12 @@ options:
default: "present" default: "present"
description: description:
- A source string state. - 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 author: Alexander Saltanov
version_added: "0.7" version_added: "0.7"
requirements: [ python-apt, python-pycurl ] requirements: [ python-apt, python-pycurl ]
@ -69,6 +75,7 @@ import re
import tempfile import tempfile
try: try:
import apt
import apt_pkg import apt_pkg
import aptsources.distro import aptsources.distro
distro = aptsources.distro.get_distro() distro = aptsources.distro.get_distro()
@ -328,6 +335,7 @@ def main():
argument_spec=dict( argument_spec=dict(
repo=dict(required=True), repo=dict(required=True),
state=dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent'], default='present'),
update_cache = dict(aliases=['update-cache'], type='bool'),
), ),
supports_check_mode=True, supports_check_mode=True,
) )
@ -340,6 +348,7 @@ def main():
repo = module.params['repo'] repo = module.params['repo']
state = module.params['state'] state = module.params['state']
update_cache = module.params['update_cache']
sourceslist = None sourceslist = None
if isinstance(distro, aptsources.distro.DebianDistribution): if isinstance(distro, aptsources.distro.DebianDistribution):
@ -365,6 +374,9 @@ def main():
if not module.check_mode and changed: if not module.check_mode and changed:
try: try:
sourceslist.save(module) sourceslist.save(module)
if update_cache:
cache = apt.Cache()
cache.update()
except OSError as err: except OSError as err:
module.fail_json(msg=unicode(err)) module.fail_json(msg=unicode(err))