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

named actions + modules list in utils.py #1308

Merged
merged 1 commit into from
Oct 12, 2012
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
1 change: 1 addition & 0 deletions lib/ansible/playbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def __init__(self,

self.inventory = ansible.inventory.Inventory(host_list)
self.inventory.subset(subset)
self.modules_list = utils.get_available_modules(self.module_path)

if not self.inventory._is_script:
self.global_vars.update(self.inventory.get_group_variables('all'))
Expand Down
11 changes: 1 addition & 10 deletions lib/ansible/playbook/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

from ansible import errors
from ansible import utils
import ansible.constants as C
import os
from os import pathsep


class Task(object):
Expand All @@ -43,14 +40,8 @@ def __init__(self, play, ds, module_vars=None):
''' constructor loads from a task or handler datastructure '''

# code to allow for saying "modulename: args" versus "action: modulename args"

modules_list = set()
for path in C.DEFAULT_MODULE_PATH.split(pathsep):
if os.path.exists(path):
modules_list.update(os.listdir(path))
modules_list = list(modules_list)
for x in ds.keys():
if x in modules_list:
if x in play.playbook.modules_list:
ds['action'] = x + " " + ds.get(x, None)
ds.pop(x)
elif not x in Task.VALID_KEYS:
Expand Down
14 changes: 14 additions & 0 deletions lib/ansible/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,17 @@ def import_plugins(directory):
if not name.startswith("_"):
modules[name] = imp.load_source(name, path)
return modules

def get_available_modules(dirname=None):
"""
returns a list of modules available based on current directory
looks in DEFAULT_MODULE_PATH, all subfolders named library and
-M option"""
modules_list = set()
if dirname is None:
dirname = C.DEFAULT_MODULE_PATH
for path in dirname.split(os.pathsep):
if os.path.exists(path):
modules_list.update(os.listdir(path))
modules_list = list(modules_list)
return modules_list