link-exists
Example:
# Make sure a symbolic link to a file/folder exists. - link-exists: src: /tmp/source dest: /tmp/dest
Description
Ensure a filesystem link from to a file/folder exists.
If the owner
and/or group
variables is/are specified, those will be created if they don't exist yet.
Variables
Name | Type | Default | Description |
---|---|---|---|
|
string | -- | The path to the target of the link. Required |
|
string | -- | The path to the file to link to. Required |
|
string | -- | The group of the link, will be created if necessary. |
|
boolean | False | Whether to create a hard link instead of a symlink. |
|
string | -- | The permissions of the link. |
|
string | -- | The owner of the link, will be created if necessary. |
|
string | -- | The permissions of the parent directory. |
Examples
Example 1
Make sure a symbolic link to a file/folder exists.
Code
- link-exists: src: /tmp/source dest: /tmp/dest
Example 2
Make sure a hard link to a file/folder exists.
Code
- link-exists: src: /tmp/source dest: /tmp/dest hard: true
Code
doc: short_help: Ensure a filesystem link exists. help: | Ensure a filesystem link from to a file/folder exists. If the ``owner`` and/or ``group`` variables is/are specified, those will be created if they don't exist yet. examples: - title: Make sure a symbolic link to a file/folder exists. vars: src: /tmp/source dest: /tmp/dest - title: Make sure a hard link to a file/folder exists. vars: src: /tmp/source dest: /tmp/dest hard: true args: src: doc: short_help: The path to the file to link to. type: string required: true dest: doc: short_help: The path to the target of the link. type: string required: true hard: doc: short_help: Whether to create a hard link instead of a symlink. type: boolean default: false required: false cli: show_default: true owner: doc: short_help: The owner of the link, will be created if necessary. type: string required: false cli: metavar: USER_NAME group: doc: short_help: The group of the link, will be created if necessary. type: string required: false cli: metavar: GROUP_NAME mode: doc: short_help: The permissions of the link. type: string required: false cli: metavar: MODE parent_dir_mode: doc: short_help: The permissions of the parent directory. type: string required: false cli: metavar: MODE 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 meta: is_interface: true tags: - link - filesystem - featured-frecklecutable frecklets: - parent-folder-exists: path: '{{:: dest ::}}' owner: '{{:: owner ::}}' group: '{{:: group ::}}' mode: '{{:: parent_dir_mode ::}}' - task: become: '{{:: owner | true_if_not_empty ::}}' frecklet: name: file type: ansible-module desc: short: "link '{{:: src ::}}' -> '{{:: dest ::}}'" long: | Create a {%:: if hard ::%}hard{%:: else ::%}symbolic{%:: endif ::%} link from {{:: src ::}} to {{:: dest ::}} (if it doesn't exist yet). {%:: if mode ::%}Ensure the link mode is '{{:: mode ::}}'{%:: else ::%}Leave link mode as is (or default if file has to be created){%:: endif ::%}. {%:: if group ::%}Set group for the link to be '{{:: group ::}}'{%:: else ::%}Use the executing users main group (or leave be if file already exists){%:: endif ::%} and {%:: if owner ::%}set owner of the link to be '{{:: owner ::}}'{%:: else ::%}use the executing users name as the owner (or leave be if file already exists){%:: endif ::%}. properties: idempotent: true internet: false elevated: '{{:: owner | true_if_not_empty ::}}' vars: src: '{{:: src ::}}' dest: '{{:: dest ::}}' owner: '{{:: owner ::}}' group: '{{:: group ::}}' mode: '{{:: mode ::}}' state: "{{:: 'hard' if hard else 'link' ::}}"
frecklecute link-exists --help Usage: frecklecute link-exists [OPTIONS] Ensure a filesystem link from to a file/folder exists. If the ``owner`` and/or ``group`` variables is/are specified, those will be created if they don't exist yet. Options: --dest DEST The path to the target of the link. [required] --src SRC The path to the file to link to. [required] --group GROUP_NAME The group of the link, will be created if necessary. --hard / --no-hard Whether to create a hard link instead of a symlink. --mode MODE The permissions of the link. --owner USER_NAME The owner of the link, will be created if necessary. --parent-dir-mode MODE The permissions of the parent directory. --help Show this message and exit.
# -*- coding: utf-8 -*- # # module path: pycklets.link_exists.LinkExists # from dataclasses import dataclass from pyckles import AutoPycklet from typing import * # noqa @dataclass class LinkExists(AutoPycklet): """Ensure a filesystem link from to a file/folder exists. If the ``owner`` and/or ``group`` variables is/are specified, those will be created if they don't exist yet. Args: dest: The path to the target of the link. group: The group of the link, will be created if necessary. hard: Whether to create a hard link instead of a symlink. mode: The permissions of the link. owner: The owner of the link, will be created if necessary. parent_dir_mode: The permissions of the parent directory. src: The path to the file to link to. """ FRECKLET_ID = "link-exists" dest: str = None group: str = None hard: bool = None mode: str = None owner: str = None parent_dir_mode: str = None src: str = None def __post_init__(self): super(LinkExists, self).__init__(var_names=["dest", "group", "hard", "mode", "owner", "parent_dir_mode", "src"]) frecklet_class = LinkExists
# -*- coding: utf-8 -*- # # module path: pycklets.link_exists.LinkExists # from pyckles import AutoPycklet class LinkExists(AutoPycklet): """Ensure a filesystem link from to a file/folder exists. If the ``owner`` and/or ``group`` variables is/are specified, those will be created if they don't exist yet. Args: dest: The path to the target of the link. group: The group of the link, will be created if necessary. hard: Whether to create a hard link instead of a symlink. mode: The permissions of the link. owner: The owner of the link, will be created if necessary. parent_dir_mode: The permissions of the parent directory. src: The path to the file to link to. """ FRECKLET_ID = "link-exists" def __init__(self, dest=None, group=None, hard=None, mode=None, owner=None, parent_dir_mode=None, src=None): super(LinkExists, self).__init__(var_names=["dest", "group", "hard", "mode", "owner", "parent_dir_mode", "src"]) self._dest = dest self._group = group self._hard = hard self._mode = mode self._owner = owner self._parent_dir_mode = parent_dir_mode self._src = src @property def dest(self): return self._dest @dest.setter def dest(self, dest): self._dest = dest @property def group(self): return self._group @group.setter def group(self, group): self._group = group @property def hard(self): return self._hard @hard.setter def hard(self, hard): self._hard = hard @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 parent_dir_mode(self): return self._parent_dir_mode @parent_dir_mode.setter def parent_dir_mode(self, parent_dir_mode): self._parent_dir_mode = parent_dir_mode @property def src(self): return self._src @src.setter def src(self, src): self._src = src frecklet_class = LinkExists