Force relative role paths to be absolute and correct errors about missing path(s). (#16088)

Addresses #10811
pull/16362/head
jctanner 9 years ago committed by James Cammarata
parent 7725c58315
commit 4cabc94f09

@ -123,7 +123,6 @@ class GalaxyCLI(CLI):
self.options, self.args =self.parser.parse_args() self.options, self.args =self.parser.parse_args()
display.verbosity = self.options.verbosity display.verbosity = self.options.verbosity
self.galaxy = Galaxy(self.options) self.galaxy = Galaxy(self.options)
return True return True
def run(self): def run(self):
@ -469,9 +468,9 @@ class GalaxyCLI(CLI):
for path in roles_path: for path in roles_path:
role_path = os.path.expanduser(path) role_path = os.path.expanduser(path)
if not os.path.exists(role_path): if not os.path.exists(role_path):
raise AnsibleOptionsError("- the path %s does not exist. Please specify a valid path with --roles-path" % roles_path) raise AnsibleOptionsError("- the path %s does not exist. Please specify a valid path with --roles-path" % role_path)
elif not os.path.isdir(role_path): elif not os.path.isdir(role_path):
raise AnsibleOptionsError("- %s exists, but it is not a directory. Please specify a valid path with --roles-path" % roles_path) raise AnsibleOptionsError("- %s exists, but it is not a directory. Please specify a valid path with --roles-path" % role_path)
path_files = os.listdir(role_path) path_files = os.listdir(role_path)
for path_file in path_files: for path_file in path_files:
gr = GalaxyRole(self.galaxy, path_file) gr = GalaxyRole(self.galaxy, path_file)

@ -39,16 +39,22 @@ def mk_boolean(value):
else: else:
return False return False
def shell_expand(path): def shell_expand(path, expand_relative_paths=False):
''' '''
shell_expand is needed as os.path.expanduser does not work shell_expand is needed as os.path.expanduser does not work
when path is None, which is the default for ANSIBLE_PRIVATE_KEY_FILE when path is None, which is the default for ANSIBLE_PRIVATE_KEY_FILE
''' '''
if path: if path:
path = os.path.expanduser(os.path.expandvars(path)) path = os.path.expanduser(os.path.expandvars(path))
if expand_relative_paths and not path.startswith('/'):
# paths are always 'relative' to the config?
if 'CONFIG_FILE' in globals():
CFGDIR = os.path.dirname(CONFIG_FILE)
path = os.path.join(CFGDIR, path)
path = os.path.abspath(path)
return path return path
def get_config(p, section, key, env_var, default, boolean=False, integer=False, floating=False, islist=False, isnone=False, ispath=False, ispathlist=False, istmppath=False): def get_config(p, section, key, env_var, default, boolean=False, integer=False, floating=False, islist=False, isnone=False, ispath=False, ispathlist=False, istmppath=False, expand_relative_paths=False):
''' return a configuration variable with casting ''' ''' return a configuration variable with casting '''
value = _get_config(p, section, key, env_var, default) value = _get_config(p, section, key, env_var, default)
if boolean: if boolean:
@ -73,7 +79,8 @@ def get_config(p, section, key, env_var, default, boolean=False, integer=False,
value = tempfile.mkdtemp(prefix='ansible-local-tmp', dir=value) value = tempfile.mkdtemp(prefix='ansible-local-tmp', dir=value)
elif ispathlist: elif ispathlist:
if isinstance(value, string_types): if isinstance(value, string_types):
value = [shell_expand(x) for x in value.split(os.pathsep)] value = [shell_expand(x, expand_relative_paths=expand_relative_paths) \
for x in value.split(os.pathsep)]
elif isinstance(value, string_types): elif isinstance(value, string_types):
value = unquote(value) value = unquote(value)
return value return value
@ -140,7 +147,7 @@ DEFAULT_PATTERN = get_config(p, DEFAULTS, 'pattern', None, None)
DEFAULT_DEBUG = get_config(p, DEFAULTS, 'debug', 'ANSIBLE_DEBUG', False, boolean=True) DEFAULT_DEBUG = get_config(p, DEFAULTS, 'debug', 'ANSIBLE_DEBUG', False, boolean=True)
DEFAULT_HOST_LIST = get_config(p, DEFAULTS,'inventory', 'ANSIBLE_INVENTORY', DEPRECATED_HOST_LIST, ispath=True) DEFAULT_HOST_LIST = get_config(p, DEFAULTS,'inventory', 'ANSIBLE_INVENTORY', DEPRECATED_HOST_LIST, ispath=True)
DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', None, ispathlist=True) DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', None, ispathlist=True)
DEFAULT_ROLES_PATH = get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', '/etc/ansible/roles', ispathlist=True) DEFAULT_ROLES_PATH = get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', '/etc/ansible/roles', ispathlist=True, expand_relative_paths=True)
DEFAULT_REMOTE_TMP = get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp') DEFAULT_REMOTE_TMP = get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp')
DEFAULT_LOCAL_TMP = get_config(p, DEFAULTS, 'local_tmp', 'ANSIBLE_LOCAL_TEMP', '$HOME/.ansible/tmp', istmppath=True) DEFAULT_LOCAL_TMP = get_config(p, DEFAULTS, 'local_tmp', 'ANSIBLE_LOCAL_TEMP', '$HOME/.ansible/tmp', istmppath=True)
DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command') DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command')

Loading…
Cancel
Save