Skip to content

Commit

Permalink
fix: use os module to get uid and gid
Browse files Browse the repository at this point in the history
  • Loading branch information
yeetypete committed Feb 10, 2025
1 parent 06fb16c commit bb2ba14
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions plugins/connection/lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,6 @@ def exec_command(self, cmd, in_data=None, sudoable=True):

return process.returncode, stdout, stderr

def _get_remote_uid_gid(self) -> tuple[int, int]:
"""Get the user and group id of 'remote_user' from the instance."""

rc, uid_out, err = self.exec_command("/bin/id -u")
if rc != 0:
raise AnsibleError(
f"Failed to get remote uid for user {self.get_option('remote_user')}: {err}"
)
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 for user {self.get_option('remote_user')}: {err}"
)
gid = gid_out.strip()

return int(uid), int(gid)

def put_file(self, in_path, out_path):
""" put a file from local to lxd """
super(Connection, self).put_file(in_path, out_path)
Expand All @@ -195,7 +176,8 @@ def put_file(self, in_path, out_path):

uid, gid = (-1, -1) # lxc file push defaults
if self.get_option("remote_user") != "root":
uid, gid = self._get_remote_uid_gid()
uid = os.getuid()
gid = os.getgid()

local_cmd.extend(
[
Expand Down

0 comments on commit bb2ba14

Please sign in to comment.