From 1280269866b46b8f769187804978759c954ac809 Mon Sep 17 00:00:00 2001 From: Andy Trevorah Date: Fri, 28 Feb 2014 16:39:06 +0000 Subject: [PATCH] apt_repository: autoinstall python-apt if not available --- library/packaging/apt_repository | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/packaging/apt_repository b/library/packaging/apt_repository index 4587d90ba7..34cdc6f4c9 100644 --- a/library/packaging/apt_repository +++ b/library/packaging/apt_repository @@ -366,7 +366,13 @@ def main(): ) if not HAVE_PYTHON_APT: - module.fail_json(msg='Could not import python modules: apt_pkg. Please install python-apt package.') + try: + module.run_command('apt-get update && apt-get install python-apt -y -q') + global apt, apt_pkg + import apt + import apt_pkg + except: + module.fail_json(msg='Could not import python modules: apt, apt_pkg. Please install python-apt package.') if not HAVE_PYCURL: module.fail_json(msg='Could not import python modules: pycurl. Please install python-pycurl package.')