Skip to content

Commit

Permalink
Fix AAP-37599
Browse files Browse the repository at this point in the history
ansible-runner will ignore adding the mountpoint to the '-v` argument list if
the source path does not exist. Instead it should respect whatever the
user is passing to the '--container-volume-mount' option. The exception would
be if the user tried to pass a file as the source path; ansible-runner should
resolve the file's parent directory.
  • Loading branch information
demonpig committed Jan 10, 2025
1 parent ec628a3 commit 601527d
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/ansible_runner/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,15 @@ def _update_volume_mount_paths(self,
dst_mount_path: str | None = None,
labels: str | None = None
) -> None:
# ensure source is abs
src_path = os.path.abspath(os.path.expanduser(os.path.expandvars(src_mount_path)))

if src_mount_path is None or not os.path.exists(src_mount_path):
logger.debug("Source volume mount path does not exist: %s", src_mount_path)
return
debug(f"Source volume mount path does not exist: {src_mount_path}")

# ensure source is abs
src_path = os.path.abspath(os.path.expanduser(os.path.expandvars(src_mount_path)))
if os.path.isfile(src_path):
debug(f"Source volume mount path '{src_path}' is a file, will resolve to parent directory: {os.path.dirname(src_path)}")
src_path = os.path.dirname(src_path)

# set dest src (if None) relative to workdir(not absolute) or provided
if dst_mount_path is None:
Expand All @@ -417,19 +419,14 @@ def _update_volume_mount_paths(self,
else:
dst_path = os.path.abspath(os.path.expanduser(os.path.expandvars(dst_mount_path)))

# ensure each is a directory not file, use src for dest
# because dest doesn't exist locally
src_dir = src_path if os.path.isdir(src_path) else os.path.dirname(src_path)
dst_dir = dst_path if os.path.isdir(src_path) else os.path.dirname(dst_path)

# always ensure a trailing slash
src_dir = os.path.join(src_dir, "")
dst_dir = os.path.join(dst_dir, "")

# ensure the src and dest are safe mount points
# after stripping off the file and resolving
self._ensure_path_safe_to_mount(src_dir)
self._ensure_path_safe_to_mount(dst_dir)
self._ensure_path_safe_to_mount(src_path)
self._ensure_path_safe_to_mount(dst_path)

# ensure that paths have a trailing slash
src_dir = os.path.join(src_path, "")
dst_dir = os.path.join(dst_path, "")

# format the src dest str
volume_mount_path = f"{src_dir}:{dst_dir}"
Expand Down

0 comments on commit 601527d

Please sign in to comment.