feat: complete placeholder _get_remote_uid_gid function

pull/9659/head
Peter Siegel 2025-02-02 02:23:54 +01:00
parent b27fdf07c7
commit cce1c3c099
No known key found for this signature in database
1 changed files with 18 additions and 3 deletions

View File

@ -163,8 +163,20 @@ class Connection(ConnectionBase):
def _get_remote_uid_gid(self) -> tuple[str, str]: def _get_remote_uid_gid(self) -> tuple[str, str]:
""" get the remote user and group id """ """Get the user and group id of 'remote_user' from the instance."""
return "1000", "1000"
rc, uid_out, err = self.exec_command("/bin/id -u")
if rc != 0:
raise AnsibleError(f"Failed to get remote uid: {err.strip()}")
uid = uid_out.strip()
rc, gid_out, err = self.exec_command("/bin/id -g")
if rc != 0:
raise AnsibleError(f"Failed to get remote gid: {err.strip()}")
gid = gid_out.strip()
return uid, gid
def put_file(self, in_path, out_path): def put_file(self, in_path, out_path):
""" put a file from local to lxd """ """ put a file from local to lxd """
@ -179,7 +191,10 @@ class Connection(ConnectionBase):
if self.get_option("project"): if self.get_option("project"):
local_cmd.extend(["--project", self.get_option("project")]) local_cmd.extend(["--project", self.get_option("project")])
uid, gid = self._get_remote_uid_gid() uid, gid = (-1, -1) # lxd default values
if self.get_option("remote_user") != "root":
uid, gid = self._get_remote_uid_gid()
local_cmd.extend([ local_cmd.extend([
"file", "push", "--uid", uid, "--gid", gid, "file", "push", "--uid", uid, "--gid", gid,
in_path, in_path,