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))
|
setattr(parser.values, option.dest, os.path.expanduser(value))
|
||||||
|
|
||||||
@staticmethod
|
@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):
|
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 '''
|
''' 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',
|
parser.add_option('-l', '--limit', default=C.DEFAULT_SUBSET, dest='subset',
|
||||||
help='further limit selected hosts to an additional pattern')
|
help='further limit selected hosts to an additional pattern')
|
||||||
|
|
||||||
if runtask_opts:
|
if module_opts:
|
||||||
parser.add_option('-M', '--module-path', dest='module_path',
|
parser.add_option('-M', '--module-path', dest='module_path', default=None,
|
||||||
help="specify path(s) to module library (default=%s)" % C.DEFAULT_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)
|
action="callback", callback=CLI.expand_tilde, type=str)
|
||||||
|
if runtask_opts:
|
||||||
parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append",
|
parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append",
|
||||||
help="set additional variables as key=value or YAML/JSON", default=[])
|
help="set additional variables as key=value or YAML/JSON", default=[])
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ class AdHocCLI(CLI):
|
||||||
runtask_opts=True,
|
runtask_opts=True,
|
||||||
vault_opts=True,
|
vault_opts=True,
|
||||||
fork_opts=True,
|
fork_opts=True,
|
||||||
|
module_opts=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# options unique to ansible ad-hoc
|
# options unique to ansible ad-hoc
|
||||||
|
@ -87,7 +88,7 @@ class AdHocCLI(CLI):
|
||||||
self.options.ask_pass = False
|
self.options.ask_pass = False
|
||||||
|
|
||||||
sshpass = None
|
sshpass = None
|
||||||
becomepass = None
|
becomepass = None
|
||||||
vault_pass = None
|
vault_pass = None
|
||||||
|
|
||||||
self.normalize_become_options()
|
self.normalize_become_options()
|
||||||
|
|
|
@ -46,10 +46,9 @@ class DocCLI(CLI):
|
||||||
self.parser = CLI.base_parser(
|
self.parser = CLI.base_parser(
|
||||||
usage='usage: %prog [options] [module...]',
|
usage='usage: %prog [options] [module...]',
|
||||||
epilog='Show Ansible module documentation',
|
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',
|
self.parser.add_option("-l", "--list", action="store_true", default=False, dest='list_dir',
|
||||||
help='List available modules')
|
help='List available modules')
|
||||||
self.parser.add_option("-s", "--snippet", action="store_true", default=False, dest='show_snippet',
|
self.parser.add_option("-s", "--snippet", action="store_true", default=False, dest='show_snippet',
|
||||||
|
|
|
@ -48,6 +48,7 @@ class PlaybookCLI(CLI):
|
||||||
runtask_opts=True,
|
runtask_opts=True,
|
||||||
vault_opts=True,
|
vault_opts=True,
|
||||||
fork_opts=True,
|
fork_opts=True,
|
||||||
|
module_opts=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ansible playbook specific opts
|
# ansible playbook specific opts
|
||||||
|
|
|
@ -53,6 +53,7 @@ class PullCLI(CLI):
|
||||||
runtask_opts=True,
|
runtask_opts=True,
|
||||||
subset_opts=True,
|
subset_opts=True,
|
||||||
inventory_opts=True,
|
inventory_opts=True,
|
||||||
|
module_opts=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# options unique to pull
|
# options unique to pull
|
||||||
|
|
|
@ -28,7 +28,6 @@ from ansible import constants as C
|
||||||
from ansible.errors import *
|
from ansible.errors import *
|
||||||
from ansible.executor.task_queue_manager import TaskQueueManager
|
from ansible.executor.task_queue_manager import TaskQueueManager
|
||||||
from ansible.playbook import Playbook
|
from ansible.playbook import Playbook
|
||||||
from ansible.plugins import module_loader
|
|
||||||
from ansible.template import Templar
|
from ansible.template import Templar
|
||||||
|
|
||||||
from ansible.utils.color import colorize, hostcolor
|
from ansible.utils.color import colorize, hostcolor
|
||||||
|
@ -52,12 +51,6 @@ class PlaybookExecutor:
|
||||||
self._options = options
|
self._options = options
|
||||||
self.passwords = passwords
|
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:
|
if options.listhosts or options.listtasks or options.listtags or options.syntax:
|
||||||
self._tqm = None
|
self._tqm = None
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -31,7 +31,7 @@ from ansible.executor.process.worker import WorkerProcess
|
||||||
from ansible.executor.process.result import ResultProcess
|
from ansible.executor.process.result import ResultProcess
|
||||||
from ansible.executor.stats import AggregateStats
|
from ansible.executor.stats import AggregateStats
|
||||||
from ansible.playbook.play_context import PlayContext
|
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
|
from ansible.template import Templar
|
||||||
|
|
||||||
__all__ = ['TaskQueueManager']
|
__all__ = ['TaskQueueManager']
|
||||||
|
@ -62,6 +62,12 @@ class TaskQueueManager:
|
||||||
self._callbacks_loaded = False
|
self._callbacks_loaded = False
|
||||||
self._callback_plugins = []
|
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
|
# a special flag to help us exit cleanly
|
||||||
self._terminated = False
|
self._terminated = False
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue