diff options
author | Brian Coca <brian.coca+git@gmail.com> | 2016-11-04 15:26:50 -0400 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2016-11-04 17:22:51 -0400 |
commit | f99060b3b9b292e2e82057b23a2520960269e160 (patch) | |
tree | 3303e57565219a36b82394ff1c9da2cd916fe652 | |
parent | 00c48637b070c072d139b6faced1d5bc5d584270 (diff) | |
download | ansible-f99060b3b9b292e2e82057b23a2520960269e160.tar.gz |
resolve inventory path on init
This allows meta refresh_inventory to work with relative paths
Added option to unfrackpath to not resolv symlinks
fixes #16857
(cherry picked from commit 8217c1c39c8de848550e2a6c816377f11cc60e9f)
-rw-r--r-- | lib/ansible/inventory/__init__.py | 5 | ||||
-rw-r--r-- | lib/ansible/utils/path.py | 25 |
2 files changed, 21 insertions, 9 deletions
diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index c1f90b9dcd..50ca53f567 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -37,8 +37,7 @@ from ansible.plugins import vars_loader from ansible.utils.unicode import to_unicode, to_bytes from ansible.utils.vars import combine_vars from ansible.parsing.utils.addresses import parse_address - -HOSTS_PATTERNS_CACHE = {} +from ansible.utils.path import unfrackpath try: from __main__ import display @@ -55,7 +54,7 @@ class Inventory(object): # the host file file, or script path, or list of hosts # if a list, inventory data will NOT be loaded - self.host_list = host_list + self.host_list = unfrackpath(host_list, follow=False) self._loader = loader self._variable_manager = variable_manager self.localhost = None diff --git a/lib/ansible/utils/path.py b/lib/ansible/utils/path.py index a89dc0a95b..20454db345 100644 --- a/lib/ansible/utils/path.py +++ b/lib/ansible/utils/path.py @@ -23,14 +23,27 @@ from ansible.utils.unicode import to_bytes __all__ = ['unfrackpath'] -def unfrackpath(path): +def unfrackpath(path, follow=True): ''' - returns a path that is free of symlinks, environment - variables, relative path traversals and symbols (~) - example: - '$HOME/../../var/mail' becomes '/var/spool/mail' + Returns a path that is free of symlinks (if follow=True), environment variables, relative path traversals and symbols (~) + + :arg path: A byte or text string representing a path to be canonicalized + :raises UnicodeDecodeError: If the canonicalized version of the path + contains non-utf8 byte sequences. + :rtype: A text string (unicode on pyyhon2, str on python3). + :returns: An absolute path with symlinks, environment variables, and tilde + expanded. Note that this does not check whether a path exists. + + example:: + '$HOME/../../var/mail' becomes '/var/spool/mail' ''' - return os.path.normpath(os.path.realpath(os.path.expanduser(os.path.expandvars(path)))) + + if follow: + final_path = os.path.normpath(os.path.realpath(os.path.expanduser(os.path.expandvars(path)))) + else: + final_path = os.path.normpath(os.path.abspath(os.path.expanduser(os.path.expandvars(path)))) + + return final_path def makedirs_safe(path, mode=None): '''Safe way to create dirs in muliprocess/thread environments''' |