sr2c.podman.podman_data role – Create the data directories a rootless Podman stack mounts as volumes

Note

This role is part of the sr2c.podman collection (version 0.0.1).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it use: ansible-galaxy collection install sr2c.podman.

To use it in a playbook, specify: sr2c.podman.podman_data.

Entry point main – Create the data directories a rootless Podman stack mounts as volumes

Synopsis

  • Creates the directories in podman_data_podman_rootless_user‘s home that the stack’s containers mount as volumes, with the owner, group and mode they need for inside the container.

  • Owners and groups are given as the IDs inside the container, and the role works out the IDs on the host from the user’s subordinate ID ranges, as reported by getsubids, so it works for users from FreeIPA as well as local users. ID 0 is the rootless user. IDs from 1 up are the user’s subordinate ranges joined in order, as Podman maps them.

  • The rootless user controls its home directory, so the directories are created with sr2c.podman.safe_directory, which refuses to follow a symbolic link anywhere below the home directory. A symbolic link where a directory or one of its parents should be fails the run. The quotas are refused, too, for a directory reached through a symbolic link under the home directory.

  • Owner, group and mode apply to each directory itself, not to its contents. Parent directories that are not listed themselves are created, if missing, owned by the rootless user with mode 0755.

  • Data directories are never removed. One taken out of podman_data_directories stays on disk, with its data, until it is removed by hand.

  • Directories with a quota get an XFS project quota, following the identifiers conventions on devops.sr2.uk. Each is a project named <stack>_<component>, where the component is the directory’s path with /, - and . turned into _, recorded in /etc/projid and /etc/projects. A project keeps its ID, and a new one gets the lowest free ID in the stack’s range, <number> x 1000 to <number> x 1000 + 999. The filesystem holding the home directory must be XFS mounted with project quotas (pquota or prjquota).

  • The projects in the stack’s namespace, named <stack> or <stack>_*, belong to this role. Any of them no longer wanted has its limit cleared, its directory taken out of the project, and its lines removed from /etc/projid and /etc/projects, as are lines in /etc/projects with an ID in the stack’s range that no wanted project uses. Projects outside the namespace are left alone. A line in /etc/projid whose name and ID disagree about which stack owns it fails the run.

  • Run sr2c.podman.podman_host for the user first.

Parameters

Parameter

Comments

podman_data_directories

dictionary

The directories, keyed by their path relative to the user’s home directory, for example opensearch-data or onlyoffice/logs. Absolute paths and .. are refused.

Each value is a dictionary with owner, group and mode, and optionally quota.

owner and group are the user and group IDs inside the container, as integers.

mode is the directory’s mode, as a quoted octal string such as "0750".

quota is the hard limit on the space the directory and everything in it may use, such as 3g, in bytes or with a k, m, g or t suffix. The soft limit is the same. It needs podman_data_stack_name and podman_data_stack_number.

Default: {}

podman_data_podman_rootless_user

string / required

The rootless Podman user whose home directory holds the data directories.

podman_data_stack_name

string

The stack name from the registry on the identifiers page, such as link. It names the stack’s XFS projects.

Required when any directory has a quota. When it is set, every project in the stack’s namespace that isn’t wanted is removed, including when no directory has a quota.

podman_data_stack_number

integer

The stack’s number from the registry on the identifiers page, such as 4 for link. The stack’s XFS project IDs are <number> x 1000 to <number> x 1000 + 999.

Required along with podman_data_stack_name.

Authors