Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plug-ins loaded from top-level plug-in directory #3018

Merged
merged 1 commit into from
May 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/ansible/utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ def _get_paths(self):
files = glob.glob("%s/*" % fullpath)
for file in files:
if os.path.isdir(file) and file not in ret:
ret.append(file)
else:
ret.append(file)
if fullpath not in ret:
ret.append(fullpath)

# look in any configured plugin paths, allow one level deep for subcategories
configured_paths = self.config.split(os.pathsep)
for path in configured_paths:
Expand Down
7 changes: 7 additions & 0 deletions test/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TestRunner(unittest.TestCase):
def setUp(self):
self.user = getpass.getuser()
self.runner = ansible.runner.Runner(
basedir='test/',
module_name='ping',
module_path='library/',
module_args='',
Expand Down Expand Up @@ -77,6 +78,12 @@ def _run(self, module_name, module_args, background=0, check_mode=False):
assert "localhost" in results['contacted']
return results['contacted']['localhost']

def test_action_plugins(self):
result = self._run("uncategorized_plugin", [])
assert result.get("msg") == "uncategorized"
result = self._run("categorized_plugin", [])
assert result.get("msg") == "categorized"

def test_ping(self):
result = self._run('ping', [])
assert "ping" in result
Expand Down
15 changes: 15 additions & 0 deletions test/action_plugins/categorized_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from ansible.runner import return_data


class ActionModule (object):
def __init__(self, runner):
self.runner = runner

def run(self, conn, tmp, module_name, module_args, inject,
complex_args=None, **kwargs):
# This plug-in should be ignored in deference to
# category/categorized_plugin.py, so it should never actually
# run.
return return_data.ReturnData(
conn=conn, comm_ok=True,
result={"msg": "this plug-in should never be run"})
11 changes: 11 additions & 0 deletions test/action_plugins/category/categorized_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ansible.runner import return_data


class ActionModule (object):
def __init__(self, runner):
self.runner = runner

def run(self, conn, tmp, module_name, module_args, inject,
complex_args=None, **kwargs):
return return_data.ReturnData(conn=conn, comm_ok=True,
result={"msg": "categorized"})
11 changes: 11 additions & 0 deletions test/action_plugins/uncategorized_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ansible.runner import return_data


class ActionModule (object):
def __init__(self, runner):
self.runner = runner

def run(self, conn, tmp, module_name, module_args, inject,
complex_args=None, **kwargs):
return return_data.ReturnData(conn=conn, comm_ok=True,
result={"msg": "uncategorized"})