folder-exists
Example:
# Create a folder if it doesn't exist yet, including owner and group if necessary. - folder-exists: path: /tmp/freckles owner: freckles group: wheel
Description
Ensure a folder exists on the filesystem
If the owner
and/or group
variables is/are specified, create those in case they don't exist yet.
If the owner
variable is specified, this frecklet will use elevated permissions.
Variables
Name | Type | Default | Description |
---|---|---|---|
|
string | -- | The path to the folder. Required |
|
boolean | True | Whether to force changing of ownership, even if folder already exists. |
|
string | -- | The group of the folder, will be created if necessary. |
|
string | -- | The permissions of the folder. |
|
string | -- | The owner of the folder, will be created if necessary. |
|
boolean | False | Whether the user (and group) should be of system user/group type. |
Examples
Example 1
Create a folder if it doesn't exist yet, including owner and group if necessary.
Code
- folder-exists: path: /tmp/freckles owner: freckles group: wheel
Example 2
Create a folder if it doesn't exist yet.
Code
- folder-exists: path: /tmp/freckles
Example 3
Create a folder incl. parent folders if necessary.
Code
- folder-exists: path: /tmp/parent_1/parent_2/freckles
Code
doc: short_help: Ensure a folder exists. help: | Ensure a folder exists on the filesystem If the ``owner`` and/or ``group`` variables is/are specified, create those in case they don't exist yet. If the ``owner`` variable is specified, this frecklet will use elevated permissions. examples: - title: Create a folder if it doesn't exist yet, including owner and group if necessary. vars: path: /tmp/freckles owner: freckles group: wheel - title: Create a folder if it doesn't exist yet. vars: path: /tmp/freckles - title: Create a folder incl. parent folders if necessary. vars: path: /tmp/parent_1/parent_2/freckles args: path: doc: short_help: The path to the folder. type: string required: true cli: param_type: argument owner: doc: short_help: The owner of the folder, will be created if necessary. type: string required: false cli: metavar: USER_NAME group: doc: short_help: The group of the folder, will be created if necessary. type: string required: false cli: metavar: GROUP_NAME mode: doc: short_help: The permissions of the folder. type: string required: false cli: metavar: MODE # become: # doc: # short_help: Whether to use root privileges to create the folder. # type: boolean # default: false # required: false # cli: # is_flag: true system_user: doc: short_help: Whether the user (and group) should be of system user/group type. type: boolean default: false required: false cli: show_default: true is_flag: true force_chown: doc: short_help: Whether to force changing of ownership, even if folder already exists. default: true required: false type: boolean cli: param_decls: - --force-chown/--no-force-chown meta: is_interface: true tags: - file - filesystem - folder - mkdir - featured-frecklecutable frecklets: - group-exists: group: '{{:: group ::}}' system_group: '{{:: system_user ::}}' frecklet::skip: "{{:: group | true_if_empty_or('root') ::}}" - user-exists: name: '{{:: owner ::}}' system_user: '{{:: system_user ::}}' frecklet::skip: "{{:: owner | true_if_empty_or('root') ::}}" - frecklet: name: folder-exists.at.yml type: ansible-tasklist resources: ansible-tasklist: - folder-exists.at.yml properties: elevated: '{{:: owner | true_if_not_empty ::}}' idemptotent: true internet: false desc: short: "create directory: {{:: path ::}}'" long: | Create folder '{{:: path ::}}' if it doesn't exist yet. Fail if '{{:: path ::}}' already exists and is not a folder. {%:: if mode ::%}Ensure the folders mode is '{{:: mode ::}}' (recursively, incl. children){%:: else ::%}Leave the folders mode as is (or default if folder has to be created){%:: endif ::%}. {%:: if group ::%}Set group (recursively, incl. children) to be '{{:: group ::}}'{%:: else ::%}Use the executing users main group (or leave be if file already exists){%:: endif ::%} and {%:: if owner ::%}set user to be '{{:: owner ::}}' (recursively){%:: else ::%}use the executing users name as the owner (or leave be if file already exists){%:: endif ::%}. references: "'file' Ansible module": https://docs.ansible.com/ansible/latest/modules/file_module.html task: become: '{{:: owner | true_if_not_empty ::}}' include-type: import vars: __path__: '{{:: path ::}}' __owner__: '{{:: owner ::}}' __group__: '{{:: group ::}}' __mode__: '{{:: mode ::}}' __force_chown__: '{{:: force_chown ::}}'
frecklecute folder-exists --help Usage: frecklecute folder-exists [OPTIONS] PATH Ensure a folder exists on the filesystem If the ``owner`` and/or ``group`` variables is/are specified, create those in case they don't exist yet. If the ``owner`` variable is specified, this frecklet will use elevated permissions. Options: --force-chown / --no-force-chown Whether to force changing of ownership, even if folder already exists. --group GROUP_NAME The group of the folder, will be created if necessary. --mode MODE The permissions of the folder. --owner USER_NAME The owner of the folder, will be created if necessary. --system-user / --no-system-user Whether the user (and group) should be of system user/group type. --help Show this message and exit.
# -*- coding: utf-8 -*- # # module path: pycklets.folder_exists.FolderExists # from dataclasses import dataclass from pyckles import AutoPycklet from typing import * # noqa @dataclass class FolderExists(AutoPycklet): """Ensure a folder exists on the filesystem If the ``owner`` and/or ``group`` variables is/are specified, create those in case they don't exist yet. If the ``owner`` variable is specified, this frecklet will use elevated permissions. Args: force_chown: Whether to force changing of ownership, even if folder already exists. group: The group of the folder, will be created if necessary. mode: The permissions of the folder. owner: The owner of the folder, will be created if necessary. path: The path to the folder. system_user: Whether the user (and group) should be of system user/group type. """ FRECKLET_ID = "folder-exists" force_chown: bool = None group: str = None mode: str = None owner: str = None path: str = None system_user: bool = None def __post_init__(self): super(FolderExists, self).__init__(var_names=["force_chown", "group", "mode", "owner", "path", "system_user"]) frecklet_class = FolderExists
# -*- coding: utf-8 -*- # # module path: pycklets.folder_exists.FolderExists # from pyckles import AutoPycklet class FolderExists(AutoPycklet): """Ensure a folder exists on the filesystem If the ``owner`` and/or ``group`` variables is/are specified, create those in case they don't exist yet. If the ``owner`` variable is specified, this frecklet will use elevated permissions. Args: force_chown: Whether to force changing of ownership, even if folder already exists. group: The group of the folder, will be created if necessary. mode: The permissions of the folder. owner: The owner of the folder, will be created if necessary. path: The path to the folder. system_user: Whether the user (and group) should be of system user/group type. """ FRECKLET_ID = "folder-exists" def __init__(self, force_chown=True, group=None, mode=None, owner=None, path=None, system_user=None): super(FolderExists, self).__init__(var_names=["force_chown", "group", "mode", "owner", "path", "system_user"]) self._force_chown = force_chown self._group = group self._mode = mode self._owner = owner self._path = path self._system_user = system_user @property def force_chown(self): return self._force_chown @force_chown.setter def force_chown(self, force_chown): self._force_chown = force_chown @property def group(self): return self._group @group.setter def group(self, group): self._group = group @property def mode(self): return self._mode @mode.setter def mode(self, mode): self._mode = mode @property def owner(self): return self._owner @owner.setter def owner(self, owner): self._owner = owner @property def path(self): return self._path @path.setter def path(self, path): self._path = path @property def system_user(self): return self._system_user @system_user.setter def system_user(self, system_user): self._system_user = system_user frecklet_class = FolderExists