progfiguration.localhost#

What the nodes have to say about themselves

Submodules#

Package Contents#

Classes#

LocalhostLinux

An interface to localhost running Linux.

class progfiguration.localhost.LocalhostLinux(nodename='localhost')#

An interface to localhost running Linux.

Maintains a cache of files it has read before.

Generally, roles should use the .localhost attribute of a progfiguration.inventory.Inventory object, rather than instantiating this class themselves. That said, nothing bad will happen with multiple instances of this class.

property uptime: float#

Return system uptime in seconds

get_umask()#

Return the umask as integer

Only works on Linux … how the fuck is this not part of the standard library? <https://stackoverflow.com/questions/7150826/how-can-i-get-the-default-file-permissions-in-python>

get_file_contents(path: progfiguration.progfigtypes.AnyPathOrStr, chomp=True, refresh=False)#

Retrieve file contents

path: The path to retrieve chomp: Remove leading/trailing whitespace refresh: Ignore cache if any

chown(path: progfiguration.progfigtypes.PathOrStr, owner: int | str | None, group: int | str | None, recursive=False)#

Change the owner and/or group of a file or directory

A convenience function that can handle any combination of owner and group.

set_file_contents(path: progfiguration.progfigtypes.AnyPathOrStr, contents: str, owner: str | None = None, group: str | None = None, mode: int | None = None, dirmode: int | None = None)#
makedirs(path: progfiguration.progfigtypes.PathOrStr, owner: str | None = None, group: str | None = None, mode: int | None = None)#
cp(src: progfiguration.progfigtypes.PathOrStr, dest: progfiguration.progfigtypes.PathOrStr, owner: str | None = None, group: str | None = None, mode: int | None = None, dirmode: int | None = None)#
_template_backend(template: type, src: progfiguration.progfigtypes.PathOrStr, dest: progfiguration.progfigtypes.PathOrStr, template_args: Dict[str, Any], owner: str | None = None, group: str | None = None, mode: int | None = None, dirmode: int | None = None)#

Template a file using the appropriate backend

template(src: str, dest: str, template_args: Dict[str, Any], owner: str | None = None, group: str | None = None, mode: int | None = None, dirmode: int | None = None)#
temple(src: str, dest: str, template_args: Dict[str, Any], owner: str | None = None, group: str | None = None, mode: int | None = None, dirmode: int | None = None)#
linesinfile(file: progfiguration.progfigtypes.PathOrStr, lines: List[str], create_owner: str | None = None, create_group: str | None = None, create_mode: int | None = None, create_dirmode: int | None = None, trailing_newline: bool = True)#

Ensure all lines in the input list exist in a file.

Inspired by Ansible’s lineinfile module, but simpler and less featureful

Args:

file: The file to modify lines: The lines to ensure are in the file create_owner: If the file does not exist, create it with this owner create_group: If the file does not exist, create it with this group create_mode: If the file does not exist, create it with this mode create_dirmode: If the file does not exist, create its parent directory with this mode

If the file does not exist and at least one of create_owner or create_group is specified, the file will be created with the specified owner and group, and the specified mode.

touch(file: progfiguration.progfigtypes.PathOrStr, owner: str | None = None, group: str | None = None, mode: int = 438, dirmode: int | None = None)#

Create an empty file.

If the file already exists, update its mtime.

Set the owner/group/mode, if specified, regardless of whether the file already exists.

If any parent dirs do not exist, create them as owned by owner/group with specified dirmode. (If parent dirs do exist, do not change their owners.)

get_user_primary_group(user: str)#

Get the primary group for a user.

Use the id command because it is POSIX compliant and works with non-local users and groups like LDAP etc.

write_sudoers(path: progfiguration.progfigtypes.PathOrStr, contents: str)#

Write a sudoers file.

The file is written to a temporary file and then moved into place.

You can write to /etc/sudoers this way, but it is recommended to write to /etc/sudoers.d/SOMEFILE instead.