• User Docs
  • Service Status
  • Source Code
Ansible Logo
SR2® DevOps Documentation
SR2® DevOps Documentation

Documentation

  • Ansible Conventions
  • Podman Stacks
  • Terraform

Collections:

  • Collection Index
    • Collections in the Sr2c Namespace
      • Sr2C.Apps
      • Sr2C.Core
      • Sr2C.Podman
        • Description
        • Plugin Index
        • Role Index
      • Sr2C.Terraform

Plugin indexes:

  • Index of all Filter Plugins
  • Index of all Modules
  • Index of all Roles

Reference indexes:

  • Index of all Collection Environment Variables
SR2® DevOps Documentation
  • Collection Index
  • Collections in the Sr2c Namespace
  • Sr2C.Podman
  • sr2c.podman.safe_directory module – Create a directory under a base directory without following symbolic links

sr2c.podman.safe_directory module – Create a directory under a base directory without following symbolic links

Note

This module 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.safe_directory.

New in sr2c.podman 0.0.1

  • Synopsis

  • Parameters

  • Notes

  • Examples

  • Return Values

Synopsis

  • Creates a directory at path under base, with the given owner, group and mode, along with any missing parent directories between them, without following a symbolic link anywhere below base.

  • Intended for running as root in a directory another user controls, such as a rootless Podman user’s home directory. With ansible.builtin.file, a symbolic link the user planted there, or a symbolic link in place of a parent directory, could make root create or chown something anywhere on the host. This module opens each part of the path relative to the one before it, refusing symbolic links, and changes the directory through the open file descriptor, so nothing can be swapped in between the check and the change.

  • base itself is trusted and may be reached through a symbolic link, such as /home pointing at /var/home.

  • Owner, group and mode apply to the directory itself, not to its contents. Parent directories that already exist are left as they are.

  • Linux only.

Parameters

Parameter

Comments

base

path / required

The absolute path of the directory to work under, for example a user’s home directory.

It must already exist.

group

integer / required

The directory’s group, as a numeric group ID.

mode

string / required

The directory’s mode, as an octal string such as "0750".

owner

integer / required

The directory’s owner, as a numeric user ID.

parent_group

integer

The group of parent directories this module creates, as a numeric group ID.

Defaults to the group of base.

parent_mode

string

The mode of parent directories this module creates.

Default: "0755"

parent_owner

integer

The owner of parent directories this module creates, as a numeric user ID.

Defaults to the owner of base.

path

string / required

The directory to create, relative to base, for example opensearch/data.

Absolute paths, empty parts, and . or .. parts are refused.

Notes

Note

  • Supports check mode. A directory that doesn’t exist yet is reported as changed, without checking anything below it.

Examples

- name: Create a data directory owned by a subordinate UID
  sr2c.podman.safe_directory:
    base: /home/app_link
    path: opensearch/data
    owner: 200999
    group: 200999
    mode: "0750"
  become: true

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

created

list / elements=string

The parts of path this module created, outermost first.

Returned: success

Sample: ["opensearch", "opensearch/data"]

path

string

The directory’s full path.

Returned: success

Sample: "/home/app_link/opensearch/data"

Authors

  • Iain Learmonth (@irl)

Collection links

  • Issue Tracker
  • Homepage
  • Repository (Sources)
Previous Next

© Copyright © SR2 Communications Limited 2021-2026.