Skip to content

Commit

Permalink
changes for package loading of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdehaan committed Sep 26, 2014
1 parent f35ed8a commit e5116d2
Show file tree
Hide file tree
Showing 261 changed files with 21 additions and 70,591 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ graft examples/playbooks
include packaging/distutils/setup.py
include lib/ansible/module_utils/powershell.ps1
recursive-include docs *
recursive-include library *
include Makefile
include VERSION
include MANIFEST.in
2 changes: 1 addition & 1 deletion examples/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# some basic default values...

hostfile = /etc/ansible/hosts
library = /usr/share/ansible
# library_path = /usr/share/my_modules/
remote_tmp = $HOME/.ansible/tmp
pattern = *
forks = 5
Expand Down
18 changes: 1 addition & 17 deletions lib/ansible/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,6 @@ def shell_expand_path(path):

active_user = pwd.getpwuid(os.geteuid())[0]

# Needed so the RPM can call setup.py and have modules land in the
# correct location. See #1277 for discussion
if getattr(sys, "real_prefix", None):
# in a virtualenv
DIST_MODULE_PATH = os.path.join(sys.prefix, 'share/ansible/')
else:
DIST_MODULE_PATH = '/usr/share/ansible/'

# Look for modules relative to this file path
# This is so that we can find the modules when running from a local checkout
# installed as editable with `pip install -e ...` or `python setup.py develop`
local_module_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', 'library')
)
DIST_MODULE_PATH = os.pathsep.join([DIST_MODULE_PATH, local_module_path])

# check all of these extensions when looking for yaml files for things like
# group variables -- really anything we can load
YAML_FILENAME_EXTENSIONS = [ "", ".yml", ".yaml", ".json" ]
Expand All @@ -115,7 +99,7 @@ def shell_expand_path(path):

# configurable things
DEFAULT_HOST_LIST = shell_expand_path(get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/etc/ansible/hosts'))
DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', DIST_MODULE_PATH)
DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', None)
DEFAULT_ROLES_PATH = shell_expand_path(get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', '/etc/ansible/roles'))
DEFAULT_REMOTE_TMP = get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp')
DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command')
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/core
Submodule core updated 161 files
2 changes: 1 addition & 1 deletion lib/ansible/modules/extras
Submodule extras updated 106 files
2 changes: 1 addition & 1 deletion lib/ansible/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ def _configure_module(self, conn, module_name, module_args, inject, complex_args
module_suffixes = getattr(conn, 'default_suffixes', None)
module_path = utils.plugins.module_finder.find_plugin(module_name, module_suffixes)
if module_path is None:
raise errors.AnsibleFileNotFound("module %s not found in %s" % (module_name, utils.plugins.module_finder.print_paths()))
raise errors.AnsibleFileNotFound("module %s not found in configured module paths" % (module_name))


# insert shared code and arguments into the module
Expand Down
18 changes: 15 additions & 3 deletions lib/ansible/utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ def print_paths(self):
ret.append(i)
return os.pathsep.join(ret)

def _all_directories(self, dir):
results = []
results.append(dir)
for root, subdirs, files in os.walk(dir):
if '__init__.py' in files:
for x in subdirs:
results.append(os.path.join(root,x))
return results

def _get_package_paths(self):
''' Gets the path of a Python package '''

Expand All @@ -85,7 +94,7 @@ def _get_package_paths(self):
m = __import__(self.package)
parts = self.package.split('.')[1:]
self.package_path = os.path.join(os.path.dirname(m.__file__), *parts)
paths.append(self.package_path)
paths.extend(self._all_directories(self.package_path))
return paths
else:
return [ self.package_path ]
Expand All @@ -107,7 +116,8 @@ def _get_paths(self):
# allow directories to be two levels deep
files2 = glob.glob("%s/*/*" % fullpath)

files = files.extend(files2)
if files2 is not None:
files.extend(files2)

for file in files:
if os.path.isdir(file) and file not in ret:
Expand All @@ -128,6 +138,8 @@ def _get_paths(self):

# look for any plugins installed in the package subtree
ret.extend(self._get_package_paths())
package_dirs = self._get_package_paths()


self._paths = ret

Expand All @@ -153,7 +165,7 @@ def find_plugin(self, name, suffixes=None):
if self.class_name:
suffixes = ['.py']
else:
suffixes = ['', '.ps1']
suffixes = ['', '.ps1', '.py']

for suffix in suffixes:
full_name = '%s%s' % (name, suffix)
Expand Down
Loading

0 comments on commit e5116d2

Please sign in to comment.