From 74baba9da6d03f0328ef81dce1ad169b3f263332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Tosser?= Date: Thu, 29 Oct 2026 08:52:33 +0100 Subject: [PATCH] fix(files): support numeric ownership idempotently --- src/pyinfra/facts/files.py | 39 ++++++-- src/pyinfra/operations/files.py | 90 +++++++++++-------- src/pyinfra/operations/util/files.py | 14 +-- tests/facts/files.Directory/file.json | 4 +- tests/facts/files.Directory/link.json | 4 +- tests/facts/files.Directory/ls_fallback.json | 7 +- .../files.Directory/ls_fallback_freebsd.json | 7 +- .../files.Directory/ls_fallback_macos.json | 7 +- tests/facts/files.Directory/valid.json | 6 +- tests/facts/files.File/directory.json | 4 +- tests/facts/files.File/invalid_output.json | 2 +- tests/facts/files.File/link.json | 4 +- tests/facts/files.File/ls_fallback.json | 7 +- .../facts/files.File/ls_fallback_selinux.json | 7 +- tests/facts/files.File/ls_fallback_time.json | 7 +- .../facts/files.File/mode_setgid_setuid.json | 6 +- tests/facts/files.File/mode_sticky.json | 6 +- tests/facts/files.File/tilde.json | 6 +- tests/facts/files.File/tilde_with_space.json | 6 +- tests/facts/files.File/valid.json | 6 +- .../facts/files.File/valid_needs_quotes.json | 6 +- tests/facts/files.File/valid_with_space.json | 6 +- tests/facts/files.Link/directory.json | 4 +- tests/facts/files.Link/file.json | 4 +- tests/facts/files.Link/ls_fallback.json | 7 +- tests/facts/files.Link/valid.json | 6 +- tests/facts/files.Link/valid_centos6.json | 6 +- tests/facts/files.Link/valid_uutils.json | 6 +- .../files.directory/numeric_owner_match.yaml | 14 +++ .../numeric_owner_mismatch.yaml | 14 +++ .../files.directory/zero_owner_add.yaml | 11 +++ .../files.download/numeric_owner_match.yaml | 15 ++++ .../numeric_owner_mismatch.yaml | 15 ++++ .../files.file/numeric_owner_match.yaml | 14 +++ .../files.file/numeric_owner_mismatch.yaml | 14 +++ .../files.link/numeric_owner_match.yaml | 16 ++++ .../files.link/numeric_owner_mismatch.yaml | 16 ++++ .../files.put/numeric_owner_match.yaml | 23 +++++ .../files.put/numeric_owner_mismatch.yaml | 23 +++++ 39 files changed, 363 insertions(+), 96 deletions(-) create mode 100644 tests/operations/files.directory/numeric_owner_match.yaml create mode 100644 tests/operations/files.directory/numeric_owner_mismatch.yaml create mode 100644 tests/operations/files.directory/zero_owner_add.yaml create mode 100644 tests/operations/files.download/numeric_owner_match.yaml create mode 100644 tests/operations/files.download/numeric_owner_mismatch.yaml create mode 100644 tests/operations/files.file/numeric_owner_match.yaml create mode 100644 tests/operations/files.file/numeric_owner_mismatch.yaml create mode 100644 tests/operations/files.link/numeric_owner_match.yaml create mode 100644 tests/operations/files.link/numeric_owner_mismatch.yaml create mode 100644 tests/operations/files.put/numeric_owner_match.yaml create mode 100644 tests/operations/files.put/numeric_owner_mismatch.yaml diff --git a/src/pyinfra/facts/files.py b/src/pyinfra/facts/files.py index e37cb4932..9e943837b 100644 --- a/src/pyinfra/facts/files.py +++ b/src/pyinfra/facts/files.py @@ -24,14 +24,19 @@ from pyinfra.api.util import try_int from pyinfra.facts.util.units import parse_size -LINUX_STAT_COMMAND = "stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N'" -BSD_STAT_COMMAND = "stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY'" +LINUX_STAT_COMMAND = ( + "stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N'" +) +BSD_STAT_COMMAND = ( + "stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY'" +) LS_COMMAND = "ls -ld" +LS_ID_COMMAND = "ls -ldn" STAT_REGEX = ( r"user=(.*) group=(.*) mode=(.*) " r"atime=(-?[0-9]*) mtime=(-?[0-9]*) ctime=(-?[0-9]*) " - r"size=([0-9]*) (.*)" + r"size=([0-9]*) uid=([0-9]+) gid=([0-9]+) (.*)" ) # ls -ld output: permissions links user group size month day year/time path @@ -217,6 +222,8 @@ class FileDict(TypedDict): ctime: datetime | None user: str group: str + uid: NotRequired[int] + gid: NotRequired[int] link_target: NotRequired[str] @@ -229,6 +236,8 @@ class File(FactBase[FileDict | Literal[False] | None]): { "user": "pyinfra", "group": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 644, "size": 3928, } @@ -255,12 +264,14 @@ def command(self, path): # only stat if the path exists (file or symlink) "! (test -e {0} || test -L {0} ) || " "( {linux_stat_command} {0} 2> /dev/null || " - "{bsd_stat_command} {0} || {ls_command} {0} )" + "{bsd_stat_command} {0} || " + "( {ls_command} {0} && {ls_id_command} {0} ) )" ), path, linux_stat_command=LINUX_STAT_COMMAND, bsd_stat_command=BSD_STAT_COMMAND, ls_command=LS_COMMAND, + ls_id_command=LS_ID_COMMAND, ) @override @@ -274,6 +285,8 @@ def process(self, output) -> FileDict | Literal[False] | None: data: FileDict = { "user": match.group(1), "group": match.group(2), + "uid": int(match.group(8)), + "gid": int(match.group(9)), "mode": _parse_mode(mode[1:]), "atime": _parse_datetime(match.group(4)), "mtime": _parse_datetime(match.group(5)), @@ -285,7 +298,7 @@ def process(self, output) -> FileDict | Literal[False] | None: return False if path_type == "link": - filename = match.group(8) + filename = match.group(10) filename, target = filename.split(" -> ") data["link_target"] = _unquote_stat_name(target) @@ -299,6 +312,16 @@ def process(self, output) -> FileDict | Literal[False] | None: if path_type != self.type: return False + if len(output) > 1: + numeric_ls_result = _parse_ls_output(output[1]) + if numeric_ls_result is not None: + numeric_data, _ = numeric_ls_result + numeric_user = numeric_data["user"] + numeric_group = numeric_data["group"] + if numeric_user.isdigit() and numeric_group.isdigit(): + data["uid"] = int(numeric_user) + data["gid"] = int(numeric_group) + return data return None @@ -313,6 +336,8 @@ class Link(File): { "user": "pyinfra", "group": "pyinfra", + "uid": 1000, + "gid": 1000, "link_target": "/path/to/link/target" } @@ -335,6 +360,8 @@ class Directory(File): { "user": "pyinfra", "group": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 644, } @@ -357,6 +384,8 @@ class Socket(File): { "user": "pyinfra", "group": "pyinfra", + "uid": 1000, + "gid": 1000, } If the path does not exist: diff --git a/src/pyinfra/operations/files.py b/src/pyinfra/operations/files.py index 6d45349be..4a12b2c5d 100644 --- a/src/pyinfra/operations/files.py +++ b/src/pyinfra/operations/files.py @@ -49,6 +49,7 @@ Directory, File, FileContents, + FileDict, FindFiles, FindInFile, FindLinks, @@ -76,12 +77,30 @@ ) +def _get_ownership_changes( + info: FileDict, + user: str | int | None, + group: str | int | None, +) -> tuple[bool, bool]: + user_changed = ( + info.get("uid") != user + if isinstance(user, int) + else user is not None and info["user"] != user + ) + group_changed = ( + info.get("gid") != group + if isinstance(group, int) + else group is not None and info["group"] != group + ) + return user_changed, group_changed + + @operation() def download( src: str, dest: str, - user: str | None = None, - group: str | None = None, + user: str | int | None = None, + group: str | int | None = None, mode: int | str | None = None, cache_time: int | None = None, force=False, @@ -102,8 +121,8 @@ def download( + src: source URL of the file + dest: where to save the file - + user: user to own the files - + group: group to own the files + + user: username or UID to own the files + + group: group name or GID to own the files + mode: permissions of the files + cache_time: if the file exists already, re-download after this time (in seconds) + force: always download the file, even if it already exists @@ -240,7 +259,7 @@ def download( yield StringCommand("mv", QuoteString(temp_file), QuoteString(dest)) - if user or group: + if user is not None or group is not None: yield file_utils.chown(dest, user, group) if mode: @@ -293,7 +312,7 @@ def download( assert info is not None # narrowed: download=True covers info is None changed = False - if (user and info["user"] != user) or (group and info["group"] != group): + if any(_get_ownership_changes(info, user, group)): yield file_utils.chown(dest, user, group) changed = True @@ -1015,8 +1034,8 @@ def _times_differ_in_s(ref, cand): def put( src: str | IO[Any], dest: str, - user: str | None = None, - group: str | None = None, + user: str | int | None = None, + group: str | int | None = None, mode: int | str | bool | None = None, add_deploy_dir=True, create_remote_dir=True, @@ -1030,8 +1049,8 @@ def put( + src: filename or IO-like object to upload + dest: remote filename to upload to - + user: user to own the files - + group: group to own the files + + user: username or UID to own the files + + group: group name or GID to own the files + mode: permissions of the files, use ``True`` to copy the local file + add_deploy_dir: src is relative to the deploy directory + create_remote_dir: create the remote directory if it doesn't exist @@ -1182,7 +1201,7 @@ def put( remote_temp_filename=host.get_temp_filename(dest, temp_directory=temp_dir), ) - if user or group: + if user is not None or group is not None: yield file_utils.chown(dest, user, group) if mode: @@ -1229,7 +1248,7 @@ def put( remote_temp_filename=host.get_temp_filename(dest, temp_directory=temp_dir), ) - if user or group: + if user is not None or group is not None: yield file_utils.chown(dest, user, group) if mode: @@ -1261,16 +1280,17 @@ def put( changed = True # Check user/group - if (user and remote_file["user"] != user) or (group and remote_file["group"] != group): + user_changed, group_changed = _get_ownership_changes(remote_file, user, group) + if user_changed or group_changed: if state.config.DIFF: old_status = [remote_file["user"], remote_file["group"]] new_status = [user, group] - if user and remote_file["user"] != user: + if user_changed: old_status[0] = format_text(remote_file["user"], "red") - new_status[0] = format_text(user, "green") - if group and remote_file["group"] != group: + new_status[0] = format_text(str(user), "green") + if group_changed: old_status[1] = format_text(remote_file["group"], "red") - new_status[1] = format_text(group, "green") + new_status[1] = format_text(str(group), "green") logger.info("chown %s:%s", *old_status) logger.info("chown %s:%s", *new_status) @@ -1610,8 +1630,8 @@ def link( path: str, target: str | None = None, present=True, - user: str | None = None, - group: str | None = None, + user: str | int | None = None, + group: str | int | None = None, symbolic=True, create_remote_dir=True, force=False, @@ -1624,8 +1644,8 @@ def link( + path: the name of the link + target: the file/directory the link points to + present: whether the link should exist - + user: user to own the link - + group: group to own the link + + user: username or UID to own the link + + group: group name or GID to own the link + symbolic: whether to make a symbolic link (vs hard link) + create_remote_dir: create the remote directory if it doesn't exist + force: if the target exists and is not a file, move or remove it and continue @@ -1698,7 +1718,7 @@ def link( yield add_cmd - if user or group: + if user is not None or group is not None: yield file_utils.chown(path, user, group, dereference=False) else: # edit @@ -1711,7 +1731,7 @@ def link( yield add_cmd # Check user/group - if (user and info["user"] != user) or (group and info["group"] != group): + if any(_get_ownership_changes(info, user, group)): yield file_utils.chown(path, user, group, dereference=False) changed = True @@ -1723,8 +1743,8 @@ def link( def file( path: str, present=True, - user: str | None = None, - group: str | None = None, + user: str | int | None = None, + group: str | int | None = None, mode: int | str | None = None, touch=False, create_remote_dir=True, @@ -1737,8 +1757,8 @@ def file( + path: name/path of the remote file + present: whether the file should exist - + user: user to own the files - + group: group to own the files + + user: username or UID to own the files + + group: group name or GID to own the files + mode: permissions of the files as an integer, eg: 755 + touch: whether to touch the file + create_remote_dir: create the remote directory if it doesn't exist @@ -1797,7 +1817,7 @@ def file( if mode: yield file_utils.chmod(path, mode) - if user or group: + if user is not None or group is not None: yield file_utils.chown(path, user, group) else: # update @@ -1813,7 +1833,7 @@ def file( changed = True # Check user/group - if (user and info["user"] != user) or (group and info["group"] != group): + if any(_get_ownership_changes(info, user, group)): yield file_utils.chown(path, user, group) changed = True @@ -1825,8 +1845,8 @@ def file( def directory( path: str, present=True, - user: str | None = None, - group: str | None = None, + user: str | int | None = None, + group: str | int | None = None, mode: int | str | None = None, recursive=False, force=False, @@ -1840,8 +1860,8 @@ def directory( + path: path of the remote folder + present: whether the folder should exist - + user: user to own the folder - + group: group to own the folder + + user: username or UID to own the folder + + group: group name or GID to own the folder + mode: permissions of the folder + recursive: recursively apply user/group/mode + force: if the target exists and is not a file, move or remove it and continue @@ -1909,7 +1929,7 @@ def directory( yield StringCommand("mkdir", "-p", QuoteString(path)) if mode: yield file_utils.chmod(path, mode, recursive=recursive) - if user or group: + if user is not None or group is not None: yield file_utils.chown(path, user, group, recursive=recursive) else: # update @@ -1922,7 +1942,7 @@ def directory( yield file_utils.chmod(path, mode, recursive=recursive) changed = True - if (user and info["user"] != user) or (group and info["group"] != group): + if any(_get_ownership_changes(info, user, group)): yield file_utils.chown(path, user, group, recursive=recursive) changed = True diff --git a/src/pyinfra/operations/util/files.py b/src/pyinfra/operations/util/files.py index 3b2bcdfd3..1458a2c72 100644 --- a/src/pyinfra/operations/util/files.py +++ b/src/pyinfra/operations/util/files.py @@ -167,23 +167,23 @@ def chmod(target: str, mode: str | int, recursive=False) -> StringCommand: def chown( target: str, - user: str | None = None, - group: str | None = None, + user: str | int | None = None, + group: str | int | None = None, recursive=False, dereference=True, ) -> StringCommand: command = "chown" user_group: str | None = None - if user and group: + if user is not None and group is not None: user_group = f"{user}:{group}" - elif user: - user_group = user + elif user is not None: + user_group = str(user) - elif group: + elif group is not None: command = "chgrp" - user_group = group + user_group = str(group) if user_group is None: raise OperationError("chown() requires at least one of user or group") diff --git a/tests/facts/files.Directory/file.json b/tests/facts/files.Directory/file.json index 44accbceb..256a447ad 100644 --- a/tests/facts/files.Directory/file.json +++ b/tests/facts/files.Directory/file.json @@ -1,8 +1,8 @@ { "arg": "/path/to/a/file", - "command": "! (test -e /path/to/a/file || test -L /path/to/a/file ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /path/to/a/file 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /path/to/a/file || ls -ld /path/to/a/file )", + "command": "! (test -e /path/to/a/file || test -L /path/to/a/file ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /path/to/a/file 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /path/to/a/file || ( ls -ld /path/to/a/file && ls -ldn /path/to/a/file ) )", "output": [ - "user=pyinfra group=pyinfra mode=-rwxrwxrwx atime=1594804767 mtime=1594804767 ctime=0 size=8 '/path/to/a/file'" + "user=pyinfra group=pyinfra mode=-rwxrwxrwx atime=1594804767 mtime=1594804767 ctime=0 size=8 uid=1000 gid=1000 '/path/to/a/file'" ], "fact": false } diff --git a/tests/facts/files.Directory/link.json b/tests/facts/files.Directory/link.json index bcd4f604e..e5b998ac6 100644 --- a/tests/facts/files.Directory/link.json +++ b/tests/facts/files.Directory/link.json @@ -1,8 +1,8 @@ { "arg": "/home/pyinfra/mylink", - "command": "! (test -e /home/pyinfra/mylink || test -L /home/pyinfra/mylink ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/mylink 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/mylink || ls -ld /home/pyinfra/mylink )", + "command": "! (test -e /home/pyinfra/mylink || test -L /home/pyinfra/mylink ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/mylink 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/mylink || ( ls -ld /home/pyinfra/mylink && ls -ldn /home/pyinfra/mylink ) )", "output": [ - "user=root group=root mode=lrwxrwxrwx atime=1594804774 mtime=1594804770 ctime=0 size=6 '/home/pyinfra/mylink' -> 'file.txt'" + "user=root group=root mode=lrwxrwxrwx atime=1594804774 mtime=1594804770 ctime=0 size=6 uid=0 gid=0 '/home/pyinfra/mylink' -> 'file.txt'" ], "fact": false } diff --git a/tests/facts/files.Directory/ls_fallback.json b/tests/facts/files.Directory/ls_fallback.json index ff2b39c48..cdb5c44e5 100644 --- a/tests/facts/files.Directory/ls_fallback.json +++ b/tests/facts/files.Directory/ls_fallback.json @@ -1,12 +1,15 @@ { "arg": "/", - "command": "! (test -e / || test -L / ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' / 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' / || ls -ld / )", + "command": "! (test -e / || test -L / ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' / 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' / || ( ls -ld / && ls -ldn / ) )", "output": [ - "drwxr-xr-x 1 root root 416 Jan 1 1970 /" + "drwxr-xr-x 1 root root 416 Jan 1 1970 /", + "drwxr-xr-x 1 0 0 416 Jan 1 1970 /" ], "fact": { "group": "root", "user": "root", + "uid": 0, + "gid": 0, "mode": 755, "atime": null, "mtime": "1970-01-01T00:00:00", diff --git a/tests/facts/files.Directory/ls_fallback_freebsd.json b/tests/facts/files.Directory/ls_fallback_freebsd.json index b34ac0f8a..8d9c3835a 100644 --- a/tests/facts/files.Directory/ls_fallback_freebsd.json +++ b/tests/facts/files.Directory/ls_fallback_freebsd.json @@ -1,12 +1,15 @@ { "arg": "/compat/devuan01/var/hostlog", - "command": "! (test -e /compat/devuan01/var/hostlog || test -L /compat/devuan01/var/hostlog ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /compat/devuan01/var/hostlog 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /compat/devuan01/var/hostlog || ls -ld /compat/devuan01/var/hostlog )", + "command": "! (test -e /compat/devuan01/var/hostlog || test -L /compat/devuan01/var/hostlog ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /compat/devuan01/var/hostlog 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /compat/devuan01/var/hostlog || ( ls -ld /compat/devuan01/var/hostlog && ls -ldn /compat/devuan01/var/hostlog ) )", "output": [ - "drwxr-xr-x+ 11 root wheel 420 Mar 28 16:00 /compat/devuan01/var/hostlog" + "drwxr-xr-x+ 11 root wheel 420 Mar 28 16:00 /compat/devuan01/var/hostlog", + "drwxr-xr-x+ 11 0 0 420 Mar 28 16:00 /compat/devuan01/var/hostlog" ], "fact": { "group": "wheel", "user": "root", + "uid": 0, + "gid": 0, "mode": 755, "atime": null, "mtime": "2025-03-28T16:00:00", diff --git a/tests/facts/files.Directory/ls_fallback_macos.json b/tests/facts/files.Directory/ls_fallback_macos.json index 783aa5000..3f05c9bf4 100644 --- a/tests/facts/files.Directory/ls_fallback_macos.json +++ b/tests/facts/files.Directory/ls_fallback_macos.json @@ -1,12 +1,15 @@ { "arg": ".", - "command": "! (test -e . || test -L . ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' . 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' . || ls -ld . )", + "command": "! (test -e . || test -L . ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' . 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' . || ( ls -ld . && ls -ldn . ) )", "output": [ - "drwxr-xr-x@ 12 xonic staff 408 22 Jun 19:00 ." + "drwxr-xr-x@ 12 xonic staff 408 22 Jun 19:00 .", + "drwxr-xr-x@ 12 1000 20 408 22 Jun 19:00 ." ], "fact": { "group": "staff", "user": "xonic", + "uid": 1000, + "gid": 20, "mode": 755, "atime": null, "mtime": "2025-06-22T19:00:00", diff --git a/tests/facts/files.Directory/valid.json b/tests/facts/files.Directory/valid.json index 8e08ff151..3a199844d 100644 --- a/tests/facts/files.Directory/valid.json +++ b/tests/facts/files.Directory/valid.json @@ -1,12 +1,14 @@ { "arg": "/home/pyinfra/myd@-_ir", - "command": "! (test -e /home/pyinfra/myd@-_ir || test -L /home/pyinfra/myd@-_ir ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/myd@-_ir 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/myd@-_ir || ls -ld /home/pyinfra/myd@-_ir )", + "command": "! (test -e /home/pyinfra/myd@-_ir || test -L /home/pyinfra/myd@-_ir ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/myd@-_ir 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/myd@-_ir || ( ls -ld /home/pyinfra/myd@-_ir && ls -ldn /home/pyinfra/myd@-_ir ) )", "output": [ - "user=pyinfra group=pyinfra mode=drw-r--r-- atime=1594804583 mtime=1594804583 ctime=0 size=0 '/home/pyinfra/myd@-_ir'" + "user=pyinfra group=pyinfra mode=drw-r--r-- atime=1594804583 mtime=1594804583 ctime=0 size=0 uid=1000 gid=1000 '/home/pyinfra/myd@-_ir'" ], "fact": { "group": "pyinfra", "user": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 644, "atime": "2020-07-15T09:16:23", "mtime": "2020-07-15T09:16:23", diff --git a/tests/facts/files.File/directory.json b/tests/facts/files.File/directory.json index 1df74c38a..0b3dc4994 100644 --- a/tests/facts/files.File/directory.json +++ b/tests/facts/files.File/directory.json @@ -1,8 +1,8 @@ { "arg": "/home/pyinfra", - "command": "! (test -e /home/pyinfra || test -L /home/pyinfra ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra || ls -ld /home/pyinfra )", + "command": "! (test -e /home/pyinfra || test -L /home/pyinfra ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra || ( ls -ld /home/pyinfra && ls -ldn /home/pyinfra ) )", "output": [ - "user=root group=root mode=drw-r--r-- atime=1594804583 mtime=1594804583 ctime=0 size=0 '/home/pyinfra'" + "user=root group=root mode=drw-r--r-- atime=1594804583 mtime=1594804583 ctime=0 size=0 uid=0 gid=0 '/home/pyinfra'" ], "fact": false } diff --git a/tests/facts/files.File/invalid_output.json b/tests/facts/files.File/invalid_output.json index 630ffbdc4..4e87e5ede 100644 --- a/tests/facts/files.File/invalid_output.json +++ b/tests/facts/files.File/invalid_output.json @@ -1,6 +1,6 @@ { "arg": "/home/pyinfra/fil-@_e.txt", - "command": "! (test -e /home/pyinfra/fil-@_e.txt || test -L /home/pyinfra/fil-@_e.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/fil-@_e.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/fil-@_e.txt || ls -ld /home/pyinfra/fil-@_e.txt )", + "command": "! (test -e /home/pyinfra/fil-@_e.txt || test -L /home/pyinfra/fil-@_e.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/fil-@_e.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/fil-@_e.txt || ( ls -ld /home/pyinfra/fil-@_e.txt && ls -ldn /home/pyinfra/fil-@_e.txt ) )", "output": [ "not-gonna-match" ], diff --git a/tests/facts/files.File/link.json b/tests/facts/files.File/link.json index bcd4f604e..e5b998ac6 100644 --- a/tests/facts/files.File/link.json +++ b/tests/facts/files.File/link.json @@ -1,8 +1,8 @@ { "arg": "/home/pyinfra/mylink", - "command": "! (test -e /home/pyinfra/mylink || test -L /home/pyinfra/mylink ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/mylink 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/mylink || ls -ld /home/pyinfra/mylink )", + "command": "! (test -e /home/pyinfra/mylink || test -L /home/pyinfra/mylink ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/mylink 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/mylink || ( ls -ld /home/pyinfra/mylink && ls -ldn /home/pyinfra/mylink ) )", "output": [ - "user=root group=root mode=lrwxrwxrwx atime=1594804774 mtime=1594804770 ctime=0 size=6 '/home/pyinfra/mylink' -> 'file.txt'" + "user=root group=root mode=lrwxrwxrwx atime=1594804774 mtime=1594804770 ctime=0 size=6 uid=0 gid=0 '/home/pyinfra/mylink' -> 'file.txt'" ], "fact": false } diff --git a/tests/facts/files.File/ls_fallback.json b/tests/facts/files.File/ls_fallback.json index db4a55e7c..7b08c7803 100644 --- a/tests/facts/files.File/ls_fallback.json +++ b/tests/facts/files.File/ls_fallback.json @@ -1,12 +1,15 @@ { "arg": "/etc/hosts", - "command": "! (test -e /etc/hosts || test -L /etc/hosts ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /etc/hosts 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /etc/hosts || ls -ld /etc/hosts )", + "command": "! (test -e /etc/hosts || test -L /etc/hosts ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /etc/hosts 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /etc/hosts || ( ls -ld /etc/hosts && ls -ldn /etc/hosts ) )", "output": [ - "-rw-r--r-- 1 root root 127 Jan 1 1970 /etc/hosts" + "-rw-r--r-- 1 root root 127 Jan 1 1970 /etc/hosts", + "-rw-r--r-- 1 0 0 127 Jan 1 1970 /etc/hosts" ], "fact": { "group": "root", "user": "root", + "uid": 0, + "gid": 0, "mode": 644, "atime": null, "mtime": "1970-01-01T00:00:00", diff --git a/tests/facts/files.File/ls_fallback_selinux.json b/tests/facts/files.File/ls_fallback_selinux.json index 51f408c61..3170dd003 100644 --- a/tests/facts/files.File/ls_fallback_selinux.json +++ b/tests/facts/files.File/ls_fallback_selinux.json @@ -1,12 +1,15 @@ { "arg": "src", - "command": "! (test -e src || test -L src ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' src 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' src || ls -ld src )", + "command": "! (test -e src || test -L src ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' src 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' src || ( ls -ld src && ls -ldn src ) )", "output": [ - "-rw-r--r--. 1 src src 1024 Nov 7 19:21 src" + "-rw-r--r--. 1 src src 1024 Nov 7 19:21 src", + "-rw-r--r--. 1 1000 1000 1024 Nov 7 19:21 src" ], "fact": { "group": "src", "user": "src", + "uid": 1000, + "gid": 1000, "mode": 644, "atime": null, "mtime": "2025-11-07T19:21:00", diff --git a/tests/facts/files.File/ls_fallback_time.json b/tests/facts/files.File/ls_fallback_time.json index d981f8f98..dd2b38520 100644 --- a/tests/facts/files.File/ls_fallback_time.json +++ b/tests/facts/files.File/ls_fallback_time.json @@ -1,12 +1,15 @@ { "arg": "/tmp/recent_file", - "command": "! (test -e /tmp/recent_file || test -L /tmp/recent_file ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /tmp/recent_file 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /tmp/recent_file || ls -ld /tmp/recent_file )", + "command": "! (test -e /tmp/recent_file || test -L /tmp/recent_file ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /tmp/recent_file 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /tmp/recent_file || ( ls -ld /tmp/recent_file && ls -ldn /tmp/recent_file ) )", "output": [ - "-rw-r--r-- 1 user user 1024 Jun 26 14:30 /tmp/recent_file" + "-rw-r--r-- 1 user user 1024 Jun 26 14:30 /tmp/recent_file", + "-rw-r--r-- 1 1000 1000 1024 Jun 26 14:30 /tmp/recent_file" ], "fact": { "group": "user", "user": "user", + "uid": 1000, + "gid": 1000, "mode": 644, "atime": null, "mtime": "2025-06-26T14:30:00", diff --git a/tests/facts/files.File/mode_setgid_setuid.json b/tests/facts/files.File/mode_setgid_setuid.json index 645fb8583..d099cb376 100644 --- a/tests/facts/files.File/mode_setgid_setuid.json +++ b/tests/facts/files.File/mode_setgid_setuid.json @@ -1,12 +1,14 @@ { "arg": "file.txt", - "command": "! (test -e file.txt || test -L file.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' file.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' file.txt || ls -ld file.txt )", + "command": "! (test -e file.txt || test -L file.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' file.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' file.txt || ( ls -ld file.txt && ls -ldn file.txt ) )", "output": [ - "user=pyinfra group=pyinfra mode=-rwsr-Sr-- atime=0 mtime=0 ctime=0 size=8 'file.txt'" + "user=pyinfra group=pyinfra mode=-rwsr-Sr-- atime=0 mtime=0 ctime=0 size=8 uid=1000 gid=1000 'file.txt'" ], "fact": { "group": "pyinfra", "user": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 6744, "atime": "1970-01-01T00:00:00", "mtime": "1970-01-01T00:00:00", diff --git a/tests/facts/files.File/mode_sticky.json b/tests/facts/files.File/mode_sticky.json index b8f8b6263..660d773b6 100644 --- a/tests/facts/files.File/mode_sticky.json +++ b/tests/facts/files.File/mode_sticky.json @@ -1,12 +1,14 @@ { "arg": "file.txt", - "command": "! (test -e file.txt || test -L file.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' file.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' file.txt || ls -ld file.txt )", + "command": "! (test -e file.txt || test -L file.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' file.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' file.txt || ( ls -ld file.txt && ls -ldn file.txt ) )", "output": [ - "user=pyinfra group=pyinfra mode=-rw-r--r-T atime=0 mtime=0 ctime=0 size=8 'file.txt'" + "user=pyinfra group=pyinfra mode=-rw-r--r-T atime=0 mtime=0 ctime=0 size=8 uid=1000 gid=1000 'file.txt'" ], "fact": { "group": "pyinfra", "user": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 1644, "atime": "1970-01-01T00:00:00", "mtime": "1970-01-01T00:00:00", diff --git a/tests/facts/files.File/tilde.json b/tests/facts/files.File/tilde.json index ba8880903..fb4f7ef8c 100644 --- a/tests/facts/files.File/tilde.json +++ b/tests/facts/files.File/tilde.json @@ -1,12 +1,14 @@ { "arg": "~/.bashrc", - "command": "! (test -e ~/.bashrc || test -L ~/.bashrc ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' ~/.bashrc 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' ~/.bashrc || ls -ld ~/.bashrc )", + "command": "! (test -e ~/.bashrc || test -L ~/.bashrc ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' ~/.bashrc 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' ~/.bashrc || ( ls -ld ~/.bashrc && ls -ldn ~/.bashrc ) )", "output": [ - "user=pyinfra group=pyinfra mode=-rw-r--r-- atime=1723483091 mtime=1722760187 ctime=1722760187 size=4310 '/home/pyinfra/.bashrc'" + "user=pyinfra group=pyinfra mode=-rw-r--r-- atime=1723483091 mtime=1722760187 ctime=1722760187 size=4310 uid=1000 gid=1000 '/home/pyinfra/.bashrc'" ], "fact": { "user": "pyinfra", "group": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 644, "atime": "2024-08-12T17:18:11", "mtime": "2024-08-04T08:29:47", diff --git a/tests/facts/files.File/tilde_with_space.json b/tests/facts/files.File/tilde_with_space.json index 3464d3c4e..2f98595ab 100644 --- a/tests/facts/files.File/tilde_with_space.json +++ b/tests/facts/files.File/tilde_with_space.json @@ -1,12 +1,14 @@ { "arg": "~/My Documents/file", - "command": "! (test -e ~/'My Documents/file' || test -L ~/'My Documents/file' ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' ~/'My Documents/file' 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' ~/'My Documents/file' || ls -ld ~/'My Documents/file' )", + "command": "! (test -e ~/'My Documents/file' || test -L ~/'My Documents/file' ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' ~/'My Documents/file' 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' ~/'My Documents/file' || ( ls -ld ~/'My Documents/file' && ls -ldn ~/'My Documents/file' ) )", "output": [ - "user=pyinfra group=pyinfra mode=-rw-r--r-- atime=1723484281 mtime=1723484281 ctime=1723484281 size=0 '/home/pyinfra/My Documents/file'" + "user=pyinfra group=pyinfra mode=-rw-r--r-- atime=1723484281 mtime=1723484281 ctime=1723484281 size=0 uid=1000 gid=1000 '/home/pyinfra/My Documents/file'" ], "fact": { "user": "pyinfra", "group": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 644, "atime": "2024-08-12T17:38:01", "mtime": "2024-08-12T17:38:01", diff --git a/tests/facts/files.File/valid.json b/tests/facts/files.File/valid.json index 0597c2eae..f73a1e906 100644 --- a/tests/facts/files.File/valid.json +++ b/tests/facts/files.File/valid.json @@ -1,12 +1,14 @@ { "arg": "/home/pyinfra/fil-@_e.txt", - "command": "! (test -e /home/pyinfra/fil-@_e.txt || test -L /home/pyinfra/fil-@_e.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/fil-@_e.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/fil-@_e.txt || ls -ld /home/pyinfra/fil-@_e.txt )", + "command": "! (test -e /home/pyinfra/fil-@_e.txt || test -L /home/pyinfra/fil-@_e.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/fil-@_e.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/fil-@_e.txt || ( ls -ld /home/pyinfra/fil-@_e.txt && ls -ldn /home/pyinfra/fil-@_e.txt ) )", "output": [ - "user=pyinfra group=domain users mode=-rwxrwx--- atime=1594804767 mtime=1594804767 ctime=0 size=8 '/home/pyinfra/fil-@_e.txt'" + "user=pyinfra group=domain users mode=-rwxrwx--- atime=1594804767 mtime=1594804767 ctime=0 size=8 uid=1000 gid=1000 '/home/pyinfra/fil-@_e.txt'" ], "fact": { "group": "domain users", "user": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 770, "atime": "2020-07-15T09:19:27", "mtime": "2020-07-15T09:19:27", diff --git a/tests/facts/files.File/valid_needs_quotes.json b/tests/facts/files.File/valid_needs_quotes.json index d5655f115..6c97692c6 100644 --- a/tests/facts/files.File/valid_needs_quotes.json +++ b/tests/facts/files.File/valid_needs_quotes.json @@ -1,12 +1,14 @@ { "arg": "fil () &&-@_e.txt", - "command": "! (test -e 'fil () &&-@_e.txt' || test -L 'fil () &&-@_e.txt' ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' 'fil () &&-@_e.txt' 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' 'fil () &&-@_e.txt' || ls -ld 'fil () &&-@_e.txt' )", + "command": "! (test -e 'fil () &&-@_e.txt' || test -L 'fil () &&-@_e.txt' ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' 'fil () &&-@_e.txt' 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' 'fil () &&-@_e.txt' || ( ls -ld 'fil () &&-@_e.txt' && ls -ldn 'fil () &&-@_e.txt' ) )", "output": [ - "user=pyinfra group=domain users mode=-rwxrwx--- atime=1594804767 mtime=1594804767 ctime=0 size=8 'fil () &&-@_e.txt'" + "user=pyinfra group=domain users mode=-rwxrwx--- atime=1594804767 mtime=1594804767 ctime=0 size=8 uid=1000 gid=1000 'fil () &&-@_e.txt'" ], "fact": { "group": "domain users", "user": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 770, "atime": "2020-07-15T09:19:27", "mtime": "2020-07-15T09:19:27", diff --git a/tests/facts/files.File/valid_with_space.json b/tests/facts/files.File/valid_with_space.json index 20dbcf2a6..1c696cca4 100644 --- a/tests/facts/files.File/valid_with_space.json +++ b/tests/facts/files.File/valid_with_space.json @@ -1,12 +1,14 @@ { "arg": "/home/pyinfra dir/fil-@_e.txt", - "command": "! (test -e '/home/pyinfra dir/fil-@_e.txt' || test -L '/home/pyinfra dir/fil-@_e.txt' ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' '/home/pyinfra dir/fil-@_e.txt' 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' '/home/pyinfra dir/fil-@_e.txt' || ls -ld '/home/pyinfra dir/fil-@_e.txt' )", + "command": "! (test -e '/home/pyinfra dir/fil-@_e.txt' || test -L '/home/pyinfra dir/fil-@_e.txt' ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' '/home/pyinfra dir/fil-@_e.txt' 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' '/home/pyinfra dir/fil-@_e.txt' || ( ls -ld '/home/pyinfra dir/fil-@_e.txt' && ls -ldn '/home/pyinfra dir/fil-@_e.txt' ) )", "output": [ - "user=pyinfra group=pyinfra mode=-rw-r--r-- atime=1594804348 mtime=1594804348 ctime=0 size=0 '/home/pyinfra dir/fil-@_e.txt'" + "user=pyinfra group=pyinfra mode=-rw-r--r-- atime=1594804348 mtime=1594804348 ctime=0 size=0 uid=1000 gid=1000 '/home/pyinfra dir/fil-@_e.txt'" ], "fact": { "group": "pyinfra", "user": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 644, "atime": "2020-07-15T09:12:28", "mtime": "2020-07-15T09:12:28", diff --git a/tests/facts/files.Link/directory.json b/tests/facts/files.Link/directory.json index de01d70e1..0666b2c83 100644 --- a/tests/facts/files.Link/directory.json +++ b/tests/facts/files.Link/directory.json @@ -1,8 +1,8 @@ { "arg": "/home/pyinfra/myd@-_ir", - "command": "! (test -e /home/pyinfra/myd@-_ir || test -L /home/pyinfra/myd@-_ir ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/myd@-_ir 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/myd@-_ir || ls -ld /home/pyinfra/myd@-_ir )", + "command": "! (test -e /home/pyinfra/myd@-_ir || test -L /home/pyinfra/myd@-_ir ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/myd@-_ir 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/myd@-_ir || ( ls -ld /home/pyinfra/myd@-_ir && ls -ldn /home/pyinfra/myd@-_ir ) )", "output": [ - "user=root group=root mode=drw-r--r-- atime=1594804583 mtime=1594804583 ctime=0 size=0 '/home/pyinfra/myd@-_ir'" + "user=root group=root mode=drw-r--r-- atime=1594804583 mtime=1594804583 ctime=0 size=0 uid=0 gid=0 '/home/pyinfra/myd@-_ir'" ], "fact": false } diff --git a/tests/facts/files.Link/file.json b/tests/facts/files.Link/file.json index 98f24c87b..8b570a49b 100644 --- a/tests/facts/files.Link/file.json +++ b/tests/facts/files.Link/file.json @@ -1,8 +1,8 @@ { "arg": "/home/pyinfra/fil-@_e.txt", - "command": "! (test -e /home/pyinfra/fil-@_e.txt || test -L /home/pyinfra/fil-@_e.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/fil-@_e.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/fil-@_e.txt || ls -ld /home/pyinfra/fil-@_e.txt )", + "command": "! (test -e /home/pyinfra/fil-@_e.txt || test -L /home/pyinfra/fil-@_e.txt ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/fil-@_e.txt 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/fil-@_e.txt || ( ls -ld /home/pyinfra/fil-@_e.txt && ls -ldn /home/pyinfra/fil-@_e.txt ) )", "output": [ - "user=pyinfra group=pyinfra mode=-rwxrwxrwx atime=1594804767 mtime=1594804767 ctime=0 size=8 '/home/pyinfra/fil-@_e.txt'" + "user=pyinfra group=pyinfra mode=-rwxrwxrwx atime=1594804767 mtime=1594804767 ctime=0 size=8 uid=1000 gid=1000 '/home/pyinfra/fil-@_e.txt'" ], "fact": false } diff --git a/tests/facts/files.Link/ls_fallback.json b/tests/facts/files.Link/ls_fallback.json index d4466b2ea..a805370e0 100644 --- a/tests/facts/files.Link/ls_fallback.json +++ b/tests/facts/files.Link/ls_fallback.json @@ -1,12 +1,15 @@ { "arg": "/usr/bin/vi", - "command": "! (test -e /usr/bin/vi || test -L /usr/bin/vi ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /usr/bin/vi 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /usr/bin/vi || ls -ld /usr/bin/vi )", + "command": "! (test -e /usr/bin/vi || test -L /usr/bin/vi ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /usr/bin/vi 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /usr/bin/vi || ( ls -ld /usr/bin/vi && ls -ldn /usr/bin/vi ) )", "output": [ - "lrwxrwxrwx 1 root root 12 Apr 2 2025 /usr/bin/vi -> /bin/busybox" + "lrwxrwxrwx 1 root root 12 Apr 2 2025 /usr/bin/vi -> /bin/busybox", + "lrwxrwxrwx 1 0 0 12 Apr 2 2025 /usr/bin/vi -> /bin/busybox" ], "fact": { "group": "root", "user": "root", + "uid": 0, + "gid": 0, "mode": 777, "atime": null, "mtime": "2025-04-02T00:00:00", diff --git a/tests/facts/files.Link/valid.json b/tests/facts/files.Link/valid.json index 8e932f9b3..01b2ebc7b 100644 --- a/tests/facts/files.Link/valid.json +++ b/tests/facts/files.Link/valid.json @@ -1,12 +1,14 @@ { "arg": "/home/pyinfra/my@-_link", - "command": "! (test -e /home/pyinfra/my@-_link || test -L /home/pyinfra/my@-_link ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/my@-_link 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/my@-_link || ls -ld /home/pyinfra/my@-_link )", + "command": "! (test -e /home/pyinfra/my@-_link || test -L /home/pyinfra/my@-_link ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/my@-_link 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/my@-_link || ( ls -ld /home/pyinfra/my@-_link && ls -ldn /home/pyinfra/my@-_link ) )", "output": [ - "user=pyinfra group=pyinfra mode=lrwxrwxrwx atime=1594804774 mtime=1594804770 ctime=0 size=6 '/home/pyinfra/my@-_link' -> 'my_f@-ile.txt'" + "user=pyinfra group=pyinfra mode=lrwxrwxrwx atime=1594804774 mtime=1594804770 ctime=0 size=6 uid=1000 gid=1000 '/home/pyinfra/my@-_link' -> 'my_f@-ile.txt'" ], "fact": { "group": "pyinfra", "user": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 777, "link_target": "my_f@-ile.txt", "atime": "2020-07-15T09:19:34", diff --git a/tests/facts/files.Link/valid_centos6.json b/tests/facts/files.Link/valid_centos6.json index 5c7aaddd7..5cfc25663 100644 --- a/tests/facts/files.Link/valid_centos6.json +++ b/tests/facts/files.Link/valid_centos6.json @@ -1,12 +1,14 @@ { "arg": "link", - "command": "! (test -e link || test -L link ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' link 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' link || ls -ld link )", + "command": "! (test -e link || test -L link ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' link 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' link || ( ls -ld link && ls -ldn link ) )", "output": [ - "user=root group=root mode=lrw-r--r-- atime=1594804774 mtime=1594804770 ctime=0 size=11 `link' -> `install.log'" + "user=root group=root mode=lrw-r--r-- atime=1594804774 mtime=1594804770 ctime=0 size=11 uid=0 gid=0 `link' -> `install.log'" ], "fact": { "group": "root", "user": "root", + "uid": 0, + "gid": 0, "mode": 644, "link_target": "install.log", "atime": "2020-07-15T09:19:34", diff --git a/tests/facts/files.Link/valid_uutils.json b/tests/facts/files.Link/valid_uutils.json index d80eb9ce5..3ab1605e2 100644 --- a/tests/facts/files.Link/valid_uutils.json +++ b/tests/facts/files.Link/valid_uutils.json @@ -1,12 +1,14 @@ { "arg": "/home/pyinfra/mylink", - "command": "! (test -e /home/pyinfra/mylink || test -L /home/pyinfra/mylink ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N' /home/pyinfra/mylink 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY' /home/pyinfra/mylink || ls -ld /home/pyinfra/mylink )", + "command": "! (test -e /home/pyinfra/mylink || test -L /home/pyinfra/mylink ) || ( stat -c 'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s uid=%u gid=%g %N' /home/pyinfra/mylink 2> /dev/null || stat -f 'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z uid=%u gid=%g %N%SY' /home/pyinfra/mylink || ( ls -ld /home/pyinfra/mylink && ls -ldn /home/pyinfra/mylink ) )", "output": [ - "user=pyinfra group=pyinfra mode=lrwxrwxrwx atime=1594804774 mtime=1594804770 ctime=0 size=8 \"/home/pyinfra/mylink\" -> \"file.txt\"" + "user=pyinfra group=pyinfra mode=lrwxrwxrwx atime=1594804774 mtime=1594804770 ctime=0 size=8 uid=1000 gid=1000 \"/home/pyinfra/mylink\" -> \"file.txt\"" ], "fact": { "group": "pyinfra", "user": "pyinfra", + "uid": 1000, + "gid": 1000, "mode": 777, "link_target": "file.txt", "atime": "2020-07-15T09:19:34", diff --git a/tests/operations/files.directory/numeric_owner_match.yaml b/tests/operations/files.directory/numeric_owner_match.yaml new file mode 100644 index 000000000..1a8407c75 --- /dev/null +++ b/tests/operations/files.directory/numeric_owner_match.yaml @@ -0,0 +1,14 @@ +args: + - testdir +kwargs: + user: 1000 + group: 1000 +facts: + files.Directory: + path=testdir: + user: testuser + group: testgroup + uid: 1000 + gid: 1000 +commands: [] +noop_description: directory testdir already exists diff --git a/tests/operations/files.directory/numeric_owner_mismatch.yaml b/tests/operations/files.directory/numeric_owner_mismatch.yaml new file mode 100644 index 000000000..0fa590a68 --- /dev/null +++ b/tests/operations/files.directory/numeric_owner_mismatch.yaml @@ -0,0 +1,14 @@ +args: + - testdir +kwargs: + user: 1001 + group: 1001 +facts: + files.Directory: + path=testdir: + user: testuser + group: testgroup + uid: 1000 + gid: 1000 +commands: + - chown 1001:1001 testdir diff --git a/tests/operations/files.directory/zero_owner_add.yaml b/tests/operations/files.directory/zero_owner_add.yaml new file mode 100644 index 000000000..ce6f04e30 --- /dev/null +++ b/tests/operations/files.directory/zero_owner_add.yaml @@ -0,0 +1,11 @@ +args: + - testdir +kwargs: + user: 0 + group: 0 +facts: + files.Directory: + path=testdir: null +commands: + - mkdir -p testdir + - chown 0:0 testdir diff --git a/tests/operations/files.download/numeric_owner_match.yaml b/tests/operations/files.download/numeric_owner_match.yaml new file mode 100644 index 000000000..d29974bcf --- /dev/null +++ b/tests/operations/files.download/numeric_owner_match.yaml @@ -0,0 +1,15 @@ +args: + - http://myfile +kwargs: + dest: /home/myfile + user: 1000 + group: 1000 +facts: + files.File: + path=/home/myfile: + user: testuser + group: testgroup + uid: 1000 + gid: 1000 +commands: [] +noop_description: file /home/myfile has already been downloaded diff --git a/tests/operations/files.download/numeric_owner_mismatch.yaml b/tests/operations/files.download/numeric_owner_mismatch.yaml new file mode 100644 index 000000000..e983ab8ba --- /dev/null +++ b/tests/operations/files.download/numeric_owner_mismatch.yaml @@ -0,0 +1,15 @@ +args: + - http://myfile +kwargs: + dest: /home/myfile + user: 1001 + group: 1001 +facts: + files.File: + path=/home/myfile: + user: testuser + group: testgroup + uid: 1000 + gid: 1000 +commands: + - chown 1001:1001 /home/myfile diff --git a/tests/operations/files.file/numeric_owner_match.yaml b/tests/operations/files.file/numeric_owner_match.yaml new file mode 100644 index 000000000..d501544b2 --- /dev/null +++ b/tests/operations/files.file/numeric_owner_match.yaml @@ -0,0 +1,14 @@ +args: + - testfile +kwargs: + user: 1000 + group: 1000 +facts: + files.File: + path=testfile: + user: testuser + group: testgroup + uid: 1000 + gid: 1000 +commands: [] +noop_description: file testfile already exists diff --git a/tests/operations/files.file/numeric_owner_mismatch.yaml b/tests/operations/files.file/numeric_owner_mismatch.yaml new file mode 100644 index 000000000..98cfd080f --- /dev/null +++ b/tests/operations/files.file/numeric_owner_mismatch.yaml @@ -0,0 +1,14 @@ +args: + - testfile +kwargs: + user: 1001 + group: 1001 +facts: + files.File: + path=testfile: + user: testuser + group: testgroup + uid: 1000 + gid: 1000 +commands: + - chown 1001:1001 testfile diff --git a/tests/operations/files.link/numeric_owner_match.yaml b/tests/operations/files.link/numeric_owner_match.yaml new file mode 100644 index 000000000..406f29b7a --- /dev/null +++ b/tests/operations/files.link/numeric_owner_match.yaml @@ -0,0 +1,16 @@ +args: + - testlink +kwargs: + target: /etc/init.d/nginx + user: 1000 + group: 1000 +facts: + files.Link: + path=testlink: + link_target: /etc/init.d/nginx + user: testuser + group: testgroup + uid: 1000 + gid: 1000 +commands: [] +noop_description: link testlink already exists diff --git a/tests/operations/files.link/numeric_owner_mismatch.yaml b/tests/operations/files.link/numeric_owner_mismatch.yaml new file mode 100644 index 000000000..8e7560971 --- /dev/null +++ b/tests/operations/files.link/numeric_owner_mismatch.yaml @@ -0,0 +1,16 @@ +args: + - testlink +kwargs: + target: /etc/init.d/nginx + user: 1001 + group: 1001 +facts: + files.Link: + path=testlink: + link_target: /etc/init.d/nginx + user: testuser + group: testgroup + uid: 1000 + gid: 1000 +commands: + - chown -h 1001:1001 testlink diff --git a/tests/operations/files.put/numeric_owner_match.yaml b/tests/operations/files.put/numeric_owner_match.yaml new file mode 100644 index 000000000..7bb4b8980 --- /dev/null +++ b/tests/operations/files.put/numeric_owner_match.yaml @@ -0,0 +1,23 @@ +args: + - somefile.txt + - /home/somefile.txt +kwargs: + user: 1000 + group: 1000 +local_files: + files: + somefile.txt: null + dirs: {} +facts: + files.File: + path=/home/somefile.txt: + user: testuser + group: testgroup + uid: 1000 + gid: 1000 + files.Directory: + path=/home: true + files.Sha1File: + path=/home/somefile.txt: ac2cd59a622114712b5b21081763c54bf0caacb8 +commands: [] +noop_description: file /home/somefile.txt is already uploaded diff --git a/tests/operations/files.put/numeric_owner_mismatch.yaml b/tests/operations/files.put/numeric_owner_mismatch.yaml new file mode 100644 index 000000000..d755e0c48 --- /dev/null +++ b/tests/operations/files.put/numeric_owner_mismatch.yaml @@ -0,0 +1,23 @@ +args: + - somefile.txt + - /home/somefile.txt +kwargs: + user: 1001 + group: 1001 +local_files: + files: + somefile.txt: null + dirs: {} +facts: + files.File: + path=/home/somefile.txt: + user: testuser + group: testgroup + uid: 1000 + gid: 1000 + files.Directory: + path=/home: true + files.Sha1File: + path=/home/somefile.txt: ac2cd59a622114712b5b21081763c54bf0caacb8 +commands: + - chown 1001:1001 /home/somefile.txt