Files Facts

The files facts provide information about the filesystem and it’s contents on the target host.

See also: Files Operations.

files.Block

host.get_fact(Block, path, marker=None, begin=None, end=None)

Returns a (possibly empty) list of the lines found between the markers.

[
    "xray: one",
    "alpha: two"
]
If the path doesn’t exist
returns None
If the path exists but the markers are not found
returns []

files.Directory

host.get_fact(Directory, path)

Returns information about a directory on the remote system:

{
    "user": "pyinfra",
    "group": "pyinfra",
    "mode": 644,
}
If the path does not exist:
returns None
If the path exists but is not a directory:
returns False

files.File

host.get_fact(File, path)

Returns information about a file on the remote system:

{
    "user": "pyinfra",
    "group": "pyinfra",
    "mode": 644,
    "size": 3928,
}
If the path does not exist:
returns None
If the path exists but is not a file:
returns False

files.FindDirectories

host.get_fact(FindDirectories, path, quote_path=True)

Returns a list of directories from a start path, recursively using find.

files.FindFiles

host.get_fact(FindFiles, path, quote_path=True)

Returns a list of files from a start path, recursively using find.

files.FindInFile

host.get_fact(FindInFile, path, pattern, interpolate_variables=False)

Checks for the existence of text in a file using grep. Returns a list of matching lines if the file exists, and None if the file does not.

files.Flags

host.get_fact(Flags, path)

Returns a list of the file flags set for the specified file or directory.

files.Md5File

host.get_fact(Md5File, path)

Returns an MD5 hash of a file, or None if the file does not exist.

files.Sha1File

host.get_fact(Sha1File, path)

Returns a SHA1 hash of a file. Works with both sha1sum and sha1. Returns None if the file doest not exist.

files.Sha256File

host.get_fact(Sha256File, path)

Returns a SHA256 hash of a file, or None if the file does not exist.

files.Socket

host.get_fact(Socket, path)

Returns information about a socket on the remote system:

{
    "user": "pyinfra",
    "group": "pyinfra",
}
If the path does not exist:
returns None
If the path exists but is not a socket:
returns False