Merge branch 'basedir-plugins' of git://github.com/dhozac/ansible into devel

pull/1344/merge
Michael DeHaan 12 years ago
commit f3407dec0e

@ -22,10 +22,15 @@ import os
import subprocess import subprocess
import os.path import os.path
from ansible.color import stringc from ansible.color import stringc
import ansible.constants as C
dirname = os.path.dirname(__file__) dirname = os.path.dirname(__file__)
callbacks = utils.import_plugins(os.path.join(dirname, 'callback_plugins')) callbacks = utils.import_plugins(os.path.join(dirname, 'callback_plugins'))
callbacks = [ c.CallbackModule() for c in callbacks.values() ] callbacks = [ c.CallbackModule() for c in callbacks.values() ]
def load_more_callbacks(dirname):
callbacks.extend([c.CallbackModule() for c in utils.import_plugins(dirname).values()])
for i in C.DEFAULT_CALLBACK_PLUGIN_PATH.split(os.pathsep):
load_more_callbacks(i)
cowsay = None cowsay = None
if os.getenv("ANSIBLE_NOCOWS") is not None: if os.getenv("ANSIBLE_NOCOWS") is not None:

@ -84,6 +84,11 @@ DEFAULT_REMOTE_PORT = int(get_config(p, DEFAULTS, 'remote_port', 'ANS
DEFAULT_TRANSPORT = get_config(p, DEFAULTS, 'transport', 'ANSIBLE_TRANSPORT', 'paramiko') DEFAULT_TRANSPORT = get_config(p, DEFAULTS, 'transport', 'ANSIBLE_TRANSPORT', 'paramiko')
DEFAULT_MANAGED_STR = get_config(p, DEFAULTS, 'ansible_managed', None, 'Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}') DEFAULT_MANAGED_STR = get_config(p, DEFAULTS, 'ansible_managed', None, 'Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}')
DEFAULT_ACTION_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'action_plugins', None, '/usr/share/ansible_plugins/action_plugins'))
DEFAULT_CALLBACK_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'callback_plugins', None, '/usr/share/ansible_plugins/callback_plugins'))
DEFAULT_CONNECTION_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'connection_plugins', None, '/usr/share/ansible_plugins/connection_plugins'))
DEFAULT_LOOKUP_PLUGIN_PATH = shell_expand_path(get_config(p, DEFAULTS, 'lookup_plugins', None, '/usr/share/ansible_plugins/lookup_plugins'))
# non-configurable things # non-configurable things
DEFAULT_REMOTE_PASS = None DEFAULT_REMOTE_PASS = None
DEFAULT_SUDO_PASS = None DEFAULT_SUDO_PASS = None

@ -20,6 +20,7 @@ import ansible.runner
import ansible.constants as C import ansible.constants as C
from ansible import utils from ansible import utils
from ansible import errors from ansible import errors
import ansible.callbacks
import os import os
import collections import collections
from play import Play from play import Play
@ -111,8 +112,7 @@ class PlayBook(object):
self.inventory.subset(subset) self.inventory.subset(subset)
self.modules_list = utils.get_available_modules(self.module_path) self.modules_list = utils.get_available_modules(self.module_path)
lookup_plugins_dir = os.path.join(plugins_dir, 'lookup_plugins') self.lookup_plugins_list = ansible.runner.lookup_plugin_list
self.lookup_plugins_list = utils.import_plugins(lookup_plugins_dir)
if not self.inventory._is_script: if not self.inventory._is_script:
self.global_vars.update(self.inventory.get_group_variables('all')) self.global_vars.update(self.inventory.get_group_variables('all'))
@ -120,6 +120,9 @@ class PlayBook(object):
self.basedir = os.path.dirname(playbook) self.basedir = os.path.dirname(playbook)
(self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook) (self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook)
self.module_path = self.module_path + os.pathsep + os.path.join(self.basedir, "library") self.module_path = self.module_path + os.pathsep + os.path.join(self.basedir, "library")
ansible.callbacks.load_more_callbacks(os.path.join(self.basedir, "callback_plugins"))
self.lookup_plugins_list.update(utils.import_plugins(os.path.join(self.basedir, 'lookup_plugins')))
# ***************************************************** # *****************************************************

@ -47,8 +47,13 @@ except ImportError:
dirname = os.path.dirname(__file__) dirname = os.path.dirname(__file__)
action_plugin_list = utils.import_plugins(os.path.join(dirname, 'action_plugins')) action_plugin_list = utils.import_plugins(os.path.join(dirname, 'action_plugins'))
for i in reversed(C.DEFAULT_ACTION_PLUGIN_PATH.split(os.pathsep)):
action_plugin_list.update(utils.import_plugins(i))
lookup_plugin_list = utils.import_plugins(os.path.join(dirname, 'lookup_plugins')) lookup_plugin_list = utils.import_plugins(os.path.join(dirname, 'lookup_plugins'))
for i in reversed(C.DEFAULT_LOOKUP_PLUGIN_PATH.split(os.pathsep)):
lookup_plugin_list.update(utils.import_plugins(i))
################################################ ################################################
def _executor_hook(job_queue, result_queue): def _executor_hook(job_queue, result_queue):
@ -167,6 +172,11 @@ class Runner(object):
for (k,v) in lookup_plugin_list.iteritems(): for (k,v) in lookup_plugin_list.iteritems():
self.lookup_plugins[k] = v.LookupModule(self) self.lookup_plugins[k] = v.LookupModule(self)
for (k,v) in utils.import_plugins(os.path.join(self.basedir, 'action_plugins')).iteritems():
self.action_plugins[k] = v.ActionModule(self)
for (k,v) in utils.import_plugins(os.path.join(self.basedir, 'lookup_plugins')).iteritems():
self.lookup_plugins[k] = v.LookupModule(self)
# ***************************************************** # *****************************************************
def _delete_remote_files(self, conn, files): def _delete_remote_files(self, conn, files):

@ -20,10 +20,14 @@
from ansible import utils from ansible import utils
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
import ansible.constants as C
import os
import os.path import os.path
dirname = os.path.dirname(__file__) dirname = os.path.dirname(__file__)
modules = utils.import_plugins(os.path.join(dirname, 'connection_plugins')) modules = utils.import_plugins(os.path.join(dirname, 'connection_plugins'))
for i in reversed(C.DEFAULT_CONNECTION_PLUGIN_PATH.split(os.pathsep)):
modules.update(utils.import_plugins(i))
# rename this module # rename this module
modules['paramiko'] = modules['paramiko_ssh'] modules['paramiko'] = modules['paramiko_ssh']
@ -34,11 +38,15 @@ class Connection(object):
def __init__(self, runner): def __init__(self, runner):
self.runner = runner self.runner = runner
self.modules = None
def connect(self, host, port): def connect(self, host, port):
if self.modules is None:
self.modules = modules.copy()
self.modules.update(utils.import_plugins(os.path.join(self.runner.basedir, 'connection_plugins')))
conn = None conn = None
transport = self.runner.transport transport = self.runner.transport
module = modules.get(transport, None) module = self.modules.get(transport, None)
if module is None: if module is None:
raise AnsibleError("unsupported connection type: %s" % transport) raise AnsibleError("unsupported connection type: %s" % transport)
conn = module.Connection(self.runner, host, port) conn = module.Connection(self.runner, host, port)

Loading…
Cancel
Save