1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-03-22 02:29:08 +00:00

Add podman image scp option (#970)

* Add podman image scp option

Fix #536


---------

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
Sergey 2025-08-19 23:30:35 +03:00 committed by GitHub
parent c2530a63f3
commit ee52d9de78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 226 additions and 1 deletions

View file

@ -318,6 +318,44 @@ class PodmanImagePusher:
def push_image(self, image_name, push_config):
"""Push an image to a registry."""
transport = (push_config or {}).get("transport")
# Special handling for scp transport which uses 'podman image scp'
if transport == "scp":
args = []
# Allow passing global --ssh options to podman
ssh_opts = push_config.get("ssh") if push_config else None
if ssh_opts:
args.extend(["--ssh", ssh_opts])
args.extend(["image", "scp"])
# Extra args (e.g., --quiet) if provided
if push_config.get("extra_args"):
args.extend(shlex.split(push_config["extra_args"]))
# Source image (local)
args.append(image_name)
# Destination host spec
dest = push_config.get("dest")
if not dest:
self.module.fail_json(msg="When using transport 'scp', push_args.dest must be provided")
# If user did not include '::' in dest, append it to copy into remote storage with same name
dest_spec = dest if "::" in dest else f"{dest}::"
args.append(dest_spec)
action = " ".join(args)
rc, out, err = run_podman_command(self.module, self.executable, args, ignore_errors=True)
if rc != 0:
self.module.fail_json(
msg=f"Failed to scp image {image_name} to {dest}", stdout=out, stderr=err, actions=[action]
)
return out + err, action
# Default push behavior for all other transports
args = ["push"]
self._add_auth_args(args)