Files Facts

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

Facts need to be imported before use, eg

from pyinfra.facts.files import File

files.Block

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

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

ode:: python

[

“xray: one”, “alpha: two”

]

he path doesn’t exist returns None

he path exists but the markers are not found returns []

files.Directory

host.get_fact(Directory, path)

rns information about a directory on the remote system:

ode:: python

{

“user”: “pyinfra”, “group”: “pyinfra”, “mode”: 644,

}

he path does not exist: returns None

he path exists but is not a directory: returns False

files.File

host.get_fact(File, path)

rns information about a file on the remote system:

ode:: python

{

“user”: “pyinfra”, “group”: “pyinfra”, “mode”: 644, “size”: 3928,

}

he path does not exist: returns None

he path exists but is not a file: returns False

files.FileContents

host.get_fact(FileContents, path)

rns the contents of a file as a list of lines. Works with both sha1sum and sha1. Returns ne`` if the file doest not exist.

files.FindDirectories

host.get_fact(FindDirectories, path, size=None, min_size=None, max_size=None, maxdepth=None, fname=None, iname=None, regex=None, args=None, quote_path=True)

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

files.FindFiles

host.get_fact(FindFiles, path, size=None, min_size=None, max_size=None, maxdepth=None, fname=None, iname=None, regex=None, args=None, quote_path=True)

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

files.FindInFile

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

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

files.Flags

host.get_fact(Flags, path)

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

files.Md5File

host.get_fact(Md5File, path)

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

files.Sha1File

host.get_fact(Sha1File, path)

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

files.Sha256File

host.get_fact(Sha256File, path)

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

files.Sha384File

host.get_fact(Sha384File, path)

rns a SHA384 hash of a file, or None if the file does not exist.

files.Socket

host.get_fact(Socket, path)

rns information about a socket on the remote system:

ode:: python

{

“user”: “pyinfra”, “group”: “pyinfra”,

}

he path does not exist: returns None

he path exists but is not a socket: returns False