mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Search path (#16387)
* smarter function to figure out relative paths takes list of paths in order of relevance to current task and does the dwim magic on them * shared function for action plugins using new dwim unify path construction and error info/messaging made include and role non exclusive corrected order and now smarter about tasks includes inside roles are currently broken as they don't provide the correct role data make dirname full match to avoid corner cases * migrated action plugins to new dwim function reported plugins to use exceptions instead of info * clarified needle
This commit is contained in:
parent
e04d552bc6
commit
2bb7feec6d
9 changed files with 150 additions and 65 deletions
|
@ -23,9 +23,11 @@ import os.path
|
|||
import tempfile
|
||||
import re
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.boolean import boolean
|
||||
from ansible.utils.hashing import checksum_s
|
||||
from ansible.utils.unicode import to_str
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
@ -106,20 +108,23 @@ class ActionModule(ActionBase):
|
|||
result.update(self._execute_module(tmp=tmp, task_vars=task_vars, delete_remote_tmp=False))
|
||||
self._remove_tmp_path(tmp)
|
||||
return result
|
||||
elif self._task._role is not None:
|
||||
src = self._loader.path_dwim_relative(self._task._role._role_path, 'files', src)
|
||||
else:
|
||||
src = self._loader.path_dwim_relative(self._loader.get_basedir(), 'files', src)
|
||||
|
||||
_re = None
|
||||
if regexp is not None:
|
||||
_re = re.compile(regexp)
|
||||
try:
|
||||
src = self._find_needle('files', src)
|
||||
except AnsibleError as e:
|
||||
result['failed'] = True
|
||||
result['msg'] = to_str(e)
|
||||
return result
|
||||
|
||||
if not os.path.isdir(src):
|
||||
result['failed'] = True
|
||||
result['msg'] = "Source (%s) is not a directory" % src
|
||||
return result
|
||||
|
||||
_re = None
|
||||
if regexp is not None:
|
||||
_re = re.compile(regexp)
|
||||
|
||||
# Does all work assembling the file
|
||||
path = self._assemble_from_fragments(src, delimiter, _re, ignore_hidden)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue