commit d7b79fda63fc0af00f0be6b832cca6e4981c4383 Author: Laur Ivan Date: Sat Dec 10 23:54:41 2022 +0100 feat: Add abspath to collection. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..37f76e9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2022 Laur Ivan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..df601ce --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Ansible Collection - laurivan.plugins + +A simple collection to satisfy missing functions from ansible core package. + +Currently has: + +- a filter for `abspath` + +## Usage + +Install collection locally: + +```bash +ansible-galaxy collection install laurivan.plugins -p ./collections +``` + +## Requirements + +None + +## Dependencies + +- Ansible >= 2.9.6 +- Python >= 3.8.10 diff --git a/galaxy.yml b/galaxy.yml new file mode 100644 index 0000000..fc9081b --- /dev/null +++ b/galaxy.yml @@ -0,0 +1,57 @@ +### REQUIRED + +# The namespace of the collection. This can be a company/brand/organization or product namespace under which all +# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with +# underscores or numbers and cannot contain consecutive underscores +namespace: laurivan + +# The name of the collection. Has the same character restrictions as 'namespace' +name: plugins + +# The version of the collection. Must be compatible with semantic versioning +version: 1.0.0 + +# The path to the Markdown (.md) readme file. This path is relative to the root of the collection +readme: README.md + +# A list of the collection's content authors. Can be just the name or in the format 'Full Name (url) +# @nicks:irc/im.site#channel' +authors: +- Laur Ivan + + +### OPTIONAL but strongly recommended + +# A short summary description of the collection +description: A collection of plugins useful to my roles + +# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only +# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file' +license: +- GPL-2.0-or-later + +# The path to the license file for the collection. This path is relative to the root of the collection. This key is +# mutually exclusive with 'license' +license_file: 'MIT' + +# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character +# requirements as 'namespace' and 'name' +tags: ["ansible-plugins", "path"] + +# Collections that this collection requires to be installed for it to be usable. The key of the dict is the +# collection label 'namespace.name'. The value is a version range +# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version +# range specifiers can be set and are separated by ',' +dependencies: {} + +# The URL of the originating SCM repository +repository: https://git.laurivan.com/Dev/ansible-laurivan-plugins + +# The URL to any online docs +documentation: https://git.laurivan.com/Dev/ansible-laurivan-plugins + +# The URL to the homepage of the collection/project +homepage: https://www.laurivan.com + +# The URL to the collection issue tracker +issues: https://git.laurivan.com/Dev/ansible-laurivan-plugins diff --git a/plugins/README.md b/plugins/README.md new file mode 100644 index 0000000..6541cf7 --- /dev/null +++ b/plugins/README.md @@ -0,0 +1,31 @@ +# Collections Plugins Directory + +This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that +is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that +would contain module utils and modules respectively. + +Here is an example directory of the majority of plugins currently supported by Ansible: + +``` +└── plugins + ├── action + ├── become + ├── cache + ├── callback + ├── cliconf + ├── connection + ├── filter + ├── httpapi + ├── inventory + ├── lookup + ├── module_utils + ├── modules + ├── netconf + ├── shell + ├── strategy + ├── terminal + ├── test + └── vars +``` + +A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible/2.9/plugins/plugins.html). \ No newline at end of file diff --git a/plugins/filter/abspath.yml b/plugins/filter/abspath.yml new file mode 100644 index 0000000..7fca257 --- /dev/null +++ b/plugins/filter/abspath.yml @@ -0,0 +1,22 @@ +DOCUMENTATION: + name: abspath + author: Laur Ivan + version_added: "1.0" + short_description: Make a path absolute + positional: _input + description: + - Converts the given path to a absolute path. + options: + _input: + description: A path. + type: str + required: true + +EXAMPLES: | + # foobar => ../test/me.txt + testing: "{{ '~/me.txt' | abspath }}" + otherrelpath: "{{ mypath | relpath }}" +RETURN: + _value: + description: The absolute path. + type: str \ No newline at end of file diff --git a/plugins/filter/files.py b/plugins/filter/files.py new file mode 100644 index 0000000..3f89a3b --- /dev/null +++ b/plugins/filter/files.py @@ -0,0 +1,9 @@ +from functools import partial +from ansible.utils.unicode import unicode_wrap + +class FilterModule(object): + ''' Ansible file jinja2 filters ''' + def filters(self): + return { + 'abspath': partial(unicode_wrap, os.path.abspath) + }