Skip to content

Commit 7043c64

Browse files
committed
Init module
1 parent e9405d9 commit 7043c64

File tree

9 files changed

+267
-4
lines changed

9 files changed

+267
-4
lines changed

.manala.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ project:
1818
##########
1919

2020
system:
21+
dir: /usr/share/ansible/collections/ansible_collections/manala/path
2122
git:
2223
config: |
2324
# Silence false positive dubious ownership errors

.manala/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ include $(MANALA_DIR)/.manala/docker/docker.mk
2121
##########
2222

2323
MANALA_DOCKER_COMPOSE_ENV += \
24-
MANALA_DIR=$(realpath $(MANALA_DIR)) \
25-
MANALA_CACHE_DIR=$(realpath $(shell dir=$(MANALA_DIR)/$(MANALA_CACHE_DIR) ; mkdir -p $${dir} ; echo $${dir}))
24+
MANALA_DIR=/usr/share/ansible/collections/ansible_collections/manala/path \
25+
MANALA_CACHE_DIR=/usr/share/ansible/collections/ansible_collections/manala/path/$(shell dir=$(MANALA_DIR)/$(MANALA_CACHE_DIR) ; mkdir -p $${dir} ; echo $(MANALA_CACHE_DIR))
2626

2727
# Command
2828
MANALA_DOCKER_COMMAND = run --rm

.manala/docker/compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
build:
1212
context: ..
1313
dockerfile: docker/Dockerfile
14-
image: manala-ansible-path:20240910083703
14+
image: manala-ansible-path:20240910140830
1515
volumes:
1616
- ../..:${MANALA_DIR}
1717
environment:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Manala Collection - Path
1+
# Ansible Collection - manala.path

galaxy.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
### REQUIRED
2+
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
3+
# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with
4+
# underscores or numbers and cannot contain consecutive underscores
5+
namespace: manala
6+
7+
# The name of the collection. Has the same character restrictions as 'namespace'
8+
name: path
9+
10+
# The version of the collection. Must be compatible with semantic versioning
11+
version: 1.0.0
12+
13+
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
14+
readme: README.md
15+
16+
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
17+
# @nicks:irc/im.site#channel'
18+
authors:
19+
- Manala <[email protected]>
20+
21+
22+
### OPTIONAL but strongly recommended
23+
# A short summary description of the collection
24+
description: path handling
25+
26+
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
27+
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
28+
license:
29+
- MIT
30+
31+
# The path to the license file for the collection. This path is relative to the root of the collection. This key is
32+
# mutually exclusive with 'license'
33+
license_file: LICENSE
34+
35+
# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
36+
# requirements as 'namespace' and 'name'
37+
tags:
38+
- path
39+
- tools
40+
41+
# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
42+
# collection label 'namespace.name'. The value is a version range
43+
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
44+
# range specifiers can be set and are separated by ','
45+
dependencies: {}
46+
47+
# The URL of the originating SCM repository
48+
repository: https://github.com/manala/ansible-path
49+
50+
# The URL to any online docs
51+
documentation: https://github.com/manala/ansible-path
52+
53+
# The URL to the homepage of the collection/project
54+
homepage: https://github.com/manala/ansible-path
55+
56+
# The URL to the collection issue tracker
57+
issues: https://github.com/manala/ansible-path/issues
58+
59+
# A list of file glob-like patterns used to filter any files or directories that should not be included in the build
60+
# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This
61+
# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry',
62+
# and '.git' are always filtered. Mutually exclusive with 'manifest'
63+
build_ignore:
64+
- .github
65+
- .gitignore
66+
- .DS_Store
67+
- .ansible-lint
68+
- .manala.yaml
69+
- .manala
70+
- examples
71+
- Makefile
72+
- tests
73+
74+
# A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a
75+
# list of MANIFEST.in style
76+
# L(directives,https://packaging.python.org/en/latest/guides/using-manifest-in/#manifest-in-commands). The key
77+
# 'omit_default_directives' is a boolean that controls whether the default directives are used. Mutually exclusive
78+
# with 'build_ignore'
79+
# manifest: null

meta/runtime.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
# Collections must specify a minimum required ansible version to upload
3+
# to galaxy
4+
requires_ansible: '>=2.15.0'
5+
6+
# Content that Ansible needs to load from another location or that has
7+
# been deprecated/removed
8+
# plugin_routing:
9+
# action:
10+
# redirected_plugin_name:
11+
# redirect: ns.col.new_location
12+
# deprecated_plugin_name:
13+
# deprecation:
14+
# removal_version: "4.0.0"
15+
# warning_text: |
16+
# See the porting guide on how to update your playbook to
17+
# use ns.col.another_plugin instead.
18+
# removed_plugin_name:
19+
# tombstone:
20+
# removal_version: "2.0.0"
21+
# warning_text: |
22+
# See the porting guide on how to update your playbook to
23+
# use ns.col.another_plugin instead.
24+
# become:
25+
# cache:
26+
# callback:
27+
# cliconf:
28+
# connection:
29+
# doc_fragments:
30+
# filter:
31+
# httpapi:
32+
# inventory:
33+
# lookup:
34+
# module_utils:
35+
# modules:
36+
# netconf:
37+
# shell:
38+
# strategy:
39+
# terminal:
40+
# test:
41+
# vars:
42+
43+
# Python import statements that Ansible needs to load from another location
44+
# import_redirection:
45+
# ansible_collections.ns.col.plugins.module_utils.old_location:
46+
# redirect: ansible_collections.ns.col.plugins.module_utils.new_location
47+
48+
# Groups of actions/modules that take a common set of options
49+
# action_groups:
50+
# group_name:
51+
# - module1
52+
# - module2

plugins/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

plugins/action/path.py

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
from __future__ import annotations
2+
3+
from ansible.errors import AnsibleActionFail
4+
from ansible.plugins.action import ActionBase
5+
from ansible.utils.display import Display
6+
from ansible.utils.vars import combine_vars
7+
8+
display = Display()
9+
10+
11+
class ActionModule(ActionBase):
12+
'''Handle path'''
13+
14+
def run(self, tmp=None, task_vars=None):
15+
16+
result = super(ActionModule, self).run(tmp, task_vars)
17+
18+
validation, args = self.validate_argument_spec(
19+
argument_spec={
20+
'path': {'type': 'path', 'required': True},
21+
'state': {'type': 'str', 'choices': ['present', 'absent', 'file'], 'default': 'present'},
22+
'content': {'type': 'str'},
23+
'template': {'type': 'path'},
24+
'vars': {'type': 'dict', 'default': {}},
25+
'user': {'type': 'str'},
26+
'group': {'type': 'str'},
27+
'mode': {'type': 'raw'},
28+
'validate': {'type': 'str'},
29+
},
30+
mutually_exclusive=(
31+
['content', 'template'],
32+
),
33+
)
34+
35+
if args['state'] == 'absent':
36+
display.v('Use "ansible.builtin.file" to ensure "%s" is absent.' % args['path'])
37+
result.update(
38+
self._execute_module(
39+
module_name='ansible.builtin.file',
40+
module_args={
41+
'path': args['path'],
42+
'state': args['state'],
43+
},
44+
task_vars=task_vars,
45+
)
46+
)
47+
elif (args['state'] in ['present', 'file']) and args['content'] is not None:
48+
display.v('Use "ansible.builtin.copy" to ensure "%s" content.' % args['path'])
49+
task = self._task.copy()
50+
task.args = {
51+
'dest': args['path'],
52+
'content': args['content'],
53+
'owner': args['user'],
54+
'group': args['group'],
55+
'mode': args['mode'],
56+
'validate': args['validate'],
57+
}
58+
result.update(
59+
self._shared_loader_obj.action_loader.get(
60+
'ansible.builtin.copy',
61+
task=task,
62+
connection=self._connection,
63+
play_context=self._play_context,
64+
loader=self._loader,
65+
templar=self._templar,
66+
shared_loader_obj=self._shared_loader_obj,
67+
).run(task_vars=combine_vars(task_vars, args['vars']))
68+
)
69+
elif (args['state'] in ['present', 'file']) and args['template']:
70+
display.v('Use "ansible.builtin.template" to ensure "%s" template.' % args['path'])
71+
task = self._task.copy()
72+
task.args = {
73+
'src': args['template'],
74+
'dest': args['path'],
75+
'owner': args['user'],
76+
'group': args['group'],
77+
'mode': args['mode'],
78+
'validate': args['validate'],
79+
}
80+
result.update(
81+
self._shared_loader_obj.action_loader.get(
82+
'ansible.builtin.template',
83+
task=task,
84+
connection=self._connection,
85+
play_context=self._play_context,
86+
loader=self._loader,
87+
templar=self._templar,
88+
shared_loader_obj=self._shared_loader_obj,
89+
).run(task_vars=combine_vars(task_vars, args['vars']))
90+
)
91+
elif args['state'] == 'file':
92+
raise AnsibleActionFail('one of the following is required: content, template')
93+
elif args['state'] == 'present':
94+
display.v('Use "ansible.builtin.file" to ensure "%s" is a directory.' % args['path'])
95+
result.update(
96+
self._execute_module(
97+
module_name='ansible.builtin.file',
98+
module_args={
99+
'path': args['path'],
100+
'state': 'directory',
101+
'owner': args['user'],
102+
'group': args['group'],
103+
'mode': args['mode'],
104+
},
105+
task_vars=task_vars,
106+
)
107+
)
108+
109+
return result

plugins/modules/path.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
5+
from __future__ import (absolute_import, division, print_function)
6+
__metaclass__ = type
7+
8+
DOCUMENTATION = '''
9+
---
10+
module: path
11+
short_description: Handle path
12+
description:
13+
- Handle path
14+
author:
15+
- Manala ([email protected])
16+
'''
17+
18+
EXAMPLES = '''
19+
- name: Path
20+
manala.path.path:
21+
'''

0 commit comments

Comments
 (0)