file-is-present

Example:

# Create file if it doesn't exist yet.
- file-is-present:
    path: /tmp/freckles.txt

Description

Ensure a file exists, create the necessary user (owner), as well as parent directories if necessary.

If a user needs to be created, it won't have any password set, so you might have to do that in a different (ideally earlier - to have more control) step.

If intermediate parent directories have to be created, they will inherit the owner/group information of the file to be created. If any of those parent directories already exist, they won't be touched at all.

If the owner variable is specified, this frecklet will use elevated permissions.

Variables

Name Type Default Description

path

string --

The path to the file. Required

group

string --

The group of the file.

mode

string --

The permissions of the file.

owner

string --

The owner of the file.

parent_dir_mode

string --

The permissions of the parent directory.

Examples

Example 1

Create file if it doesn't exist yet.

Code
- file-is-present:
    path: /tmp/freckles.txt
Description

Create a file as child of an existing folder. The owner will be whoever runs the frecklet.

Example 2

Create file (incl. parent folders) if it doesn't exist yet.

Code
- file-is-present:
    path: /tmp/parent_1/parent_2/freckles.txt
Description

Create folder structure /tmp/parent_1/parent_2, then create child file freckles.txt. Owner will be whoever runs the frecklet.

Example 3

Create file if it doesn't exist and make it to be executable.

Code
- file-is-present:
    path: /tmp/example_script.sh
    mode: '0775'
Description

Creates an (empty) file if it doesn't exist, sets the mode to '775'.

Example 4

Create file with custom owner & group.

Code
- file-is-present:
    path: /tmp/freckles.txt
    owner: freckles
    group: freckles
    become: true
Description

Create the user and group 'freckles' if they don't exist yet, then the file /tmp/freckles.txt and set the user/group properties to 'freckles'.

Here we need to set the become variable, because otherwise we would not have permission to create the file.

Command-line

frecklecute file-is-present --help

Usage: frecklecute file-is-present [OPTIONS] PATH

  Ensure a file exists, create the necessary user (owner), as well as parent
  directories if necessary.

  If a user needs to be created, it won't have any password set, so you
  might have to do that in a different (ideally earlier - to have more
  control) step.

  If intermediate parent directories have to be created, they will inherit
  the owner/group information of the file to be created. If any of those
  parent directories already exist, they won't be touched at all.

  If the ``owner`` variable is specified, this frecklet will use elevated
  permissions.

Options:
  --group GROUP           The group of the file.
  --mode MODE             The permissions of the file.
  --owner USER            The owner of the file.
  --parent-dir-mode MODE  The permissions of the parent directory.
  --help                  Show this message and exit.