Skip to main content
Server facts provide information about the operating system, users, processes, and system configuration of target hosts.

System Information

Hostname

Get the current hostname:
Returns: str - The hostname

Kernel

Get the kernel name:
Returns: str - Kernel name from uname -s

KernelVersion

Get the kernel version:
Returns: str - Kernel version from uname -r

Arch

Get the system architecture:
Returns: str - Architecture from uname -m

LinuxDistribution

Get detailed Linux distribution information:
Returns: dict with keys:
  • name - Distribution name (“Ubuntu”, “CentOS”, “Debian”, etc.)
  • version - Version string
  • major - Major version number
  • minor - Minor version number
  • release_meta - Additional release info

Users and Groups

User

Get current username:
Returns: str - Current username

Home

Get home directory:
Parameters:
  • user (str, optional) - Username to get home for
Returns: str - Home directory path

UsersAndGroups

Get all users and groups:
Returns: dict with:
  • users - Dict of username -> user info
  • groups - Dict of groupname -> group info

Groups

Get list of all groups:
Returns: list[str] - List of group names

Environment

Path

Get the PATH environment variable:
Returns: str - PATH variable value

TmpDir

Get the temporary directory:
Returns: str - Temporary directory path Checks in order:
  1. $TMPDIR if set and writable
  2. $TMP if set and writable
  3. $TEMP if set and writable
  4. Empty string if none available

Command Utilities

Which

Check if a command exists and get its path:
Parameters:
  • command (str, required) - Command name to locate
Returns: str | None - Full path to command, or None if not found

Command

Execute arbitrary command and get output:
Parameters:
  • command (str, required) - Command to execute
Returns: str - Command output
Prefer specific facts over Command when available. For example, use Which instead of Command(command="which nginx").

Date and Time

Date

Get current date/time:
Returns: datetime - Current date and time on the host

Processes

ProcessSnapshot

Get running processes:
Returns: dict - Process ID -> process info

System Resources

Memory

Get memory information:
Returns: dict - Memory information from /proc/meminfo

Mounts

Get mounted filesystems:
Returns: dict - Mount point -> mount info

Complete Example

Here’s a complete example using server facts:

Source Reference

Location: src/pyinfra/facts/server.py

Key Facts

  • Hostname - Get hostname (line 79)
  • Kernel - Get kernel name (line 89)
  • KernelVersion - Get kernel version (line 99)
  • Arch - Get architecture (line 137)
  • LinuxDistribution - Get distribution info
  • User - Get current user (line 23)
  • Home - Get home directory (line 33)
  • Which - Find command path
  • Command - Execute command (line 149)