From c1b38f62c86d02aff751ba7837e2511ec39fb5e7 Mon Sep 17 00:00:00 2001 From: Matt Goodall Date: Wed, 6 Jun 2012 21:42:29 +0100 Subject: [PATCH] Search multiple paths for modules. Minimal change to allow a list of paths (separated by the typical path separator) to be searched in sequence for the named module. --- lib/ansible/runner/__init__.py | 11 ++++++++--- lib/ansible/utils.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index b46ba05db71..e4ed7cb5587 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -722,9 +722,14 @@ class Runner(object): if module.startswith("/"): raise errors.AnsibleFileNotFound("%s is not a module" % module) - in_path = os.path.expanduser(os.path.join(self.module_path, module)) - if not os.path.exists(in_path): - raise errors.AnsibleFileNotFound("module not found: %s" % in_path) + + # Search module path(s) for named module. + for module_path in self.module_path.split(os.pathsep): + in_path = os.path.expanduser(os.path.join(module_path, module)) + if os.path.exists(in_path): + break + else: + raise errors.AnsibleFileNotFound("module %s not found in %s" % (module, self.module_path)) out_path = tmp + module diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index c507103d677..d9805b13047 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -323,7 +323,7 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, asyn parser.add_option('-K', '--ask-sudo-pass', default=False, dest='ask_sudo_pass', action='store_true', help='ask for sudo password') parser.add_option('-M', '--module-path', dest='module_path', - help="specify path to module library (default=%s)" % constants.DEFAULT_MODULE_PATH, + help="specify path(s) to module library (default=%s)" % constants.DEFAULT_MODULE_PATH, default=constants.DEFAULT_MODULE_PATH) parser.add_option('-T', '--timeout', default=constants.DEFAULT_TIMEOUT, type='int', dest='timeout',