pushed module_loader to task_queue_manager so all cli's can benefit from it
also normalized -M option across all cli fixes #12016
This commit is contained in:
parent
d2c948dd6a
commit
154754ae50
7 changed files with 17 additions and 15 deletions
|
@ -220,7 +220,7 @@ class CLI(object):
|
|||
setattr(parser.values, option.dest, os.path.expanduser(value))
|
||||
|
||||
@staticmethod
|
||||
def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False, vault_opts=False,
|
||||
def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False, vault_opts=False, module_opts=False,
|
||||
async_opts=False, connect_opts=False, subset_opts=False, check_opts=False, inventory_opts=False, epilog=None, fork_opts=False):
|
||||
''' create an options parser for most ansible scripts '''
|
||||
|
||||
|
@ -241,10 +241,11 @@ class CLI(object):
|
|||
parser.add_option('-l', '--limit', default=C.DEFAULT_SUBSET, dest='subset',
|
||||
help='further limit selected hosts to an additional pattern')
|
||||
|
||||
if runtask_opts:
|
||||
parser.add_option('-M', '--module-path', dest='module_path',
|
||||
help="specify path(s) to module library (default=%s)" % C.DEFAULT_MODULE_PATH, default=None,
|
||||
if module_opts:
|
||||
parser.add_option('-M', '--module-path', dest='module_path', default=None,
|
||||
help="specify path(s) to module library (default=%s)" % C.DEFAULT_MODULE_PATH,
|
||||
action="callback", callback=CLI.expand_tilde, type=str)
|
||||
if runtask_opts:
|
||||
parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append",
|
||||
help="set additional variables as key=value or YAML/JSON", default=[])
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ class AdHocCLI(CLI):
|
|||
runtask_opts=True,
|
||||
vault_opts=True,
|
||||
fork_opts=True,
|
||||
module_opts=True,
|
||||
)
|
||||
|
||||
# options unique to ansible ad-hoc
|
||||
|
@ -87,7 +88,7 @@ class AdHocCLI(CLI):
|
|||
self.options.ask_pass = False
|
||||
|
||||
sshpass = None
|
||||
becomepass = None
|
||||
becomepass = None
|
||||
vault_pass = None
|
||||
|
||||
self.normalize_become_options()
|
||||
|
|
|
@ -46,10 +46,9 @@ class DocCLI(CLI):
|
|||
self.parser = CLI.base_parser(
|
||||
usage='usage: %prog [options] [module...]',
|
||||
epilog='Show Ansible module documentation',
|
||||
module_opts=True,
|
||||
)
|
||||
|
||||
self.parser.add_option("-M", "--module-path", action="store", dest="module_path", default=C.DEFAULT_MODULE_PATH,
|
||||
help="Ansible modules/ directory")
|
||||
self.parser.add_option("-l", "--list", action="store_true", default=False, dest='list_dir',
|
||||
help='List available modules')
|
||||
self.parser.add_option("-s", "--snippet", action="store_true", default=False, dest='show_snippet',
|
||||
|
|
|
@ -48,6 +48,7 @@ class PlaybookCLI(CLI):
|
|||
runtask_opts=True,
|
||||
vault_opts=True,
|
||||
fork_opts=True,
|
||||
module_opts=True,
|
||||
)
|
||||
|
||||
# ansible playbook specific opts
|
||||
|
|
|
@ -53,6 +53,7 @@ class PullCLI(CLI):
|
|||
runtask_opts=True,
|
||||
subset_opts=True,
|
||||
inventory_opts=True,
|
||||
module_opts=True,
|
||||
)
|
||||
|
||||
# options unique to pull
|
||||
|
|
|
@ -28,7 +28,6 @@ from ansible import constants as C
|
|||
from ansible.errors import *
|
||||
from ansible.executor.task_queue_manager import TaskQueueManager
|
||||
from ansible.playbook import Playbook
|
||||
from ansible.plugins import module_loader
|
||||
from ansible.template import Templar
|
||||
|
||||
from ansible.utils.color import colorize, hostcolor
|
||||
|
@ -52,12 +51,6 @@ class PlaybookExecutor:
|
|||
self._options = options
|
||||
self.passwords = passwords
|
||||
|
||||
# make sure the module path (if specified) is parsed and
|
||||
# added to the module_loader object
|
||||
if options.module_path is not None:
|
||||
for path in options.module_path.split(os.pathsep):
|
||||
module_loader.add_directory(path)
|
||||
|
||||
if options.listhosts or options.listtasks or options.listtags or options.syntax:
|
||||
self._tqm = None
|
||||
else:
|
||||
|
|
|
@ -31,7 +31,7 @@ from ansible.executor.process.worker import WorkerProcess
|
|||
from ansible.executor.process.result import ResultProcess
|
||||
from ansible.executor.stats import AggregateStats
|
||||
from ansible.playbook.play_context import PlayContext
|
||||
from ansible.plugins import callback_loader, strategy_loader
|
||||
from ansible.plugins import callback_loader, strategy_loader, module_loader
|
||||
from ansible.template import Templar
|
||||
|
||||
__all__ = ['TaskQueueManager']
|
||||
|
@ -62,6 +62,12 @@ class TaskQueueManager:
|
|||
self._callbacks_loaded = False
|
||||
self._callback_plugins = []
|
||||
|
||||
# make sure the module path (if specified) is parsed and
|
||||
# added to the module_loader object
|
||||
if options.module_path is not None:
|
||||
for path in options.module_path.split(os.pathsep):
|
||||
module_loader.add_directory(path)
|
||||
|
||||
# a special flag to help us exit cleanly
|
||||
self._terminated = False
|
||||
|
||||
|
|
Loading…
Reference in a new issue