From 7eb7ba7dbf86c77c617d3b6f5c9668455324386c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gon=C3=A7alves?= Date: Sat, 9 Jul 2022 16:21:07 +0200 Subject: [PATCH 1/3] Create an Ansible collection --- {examples => doc/examples}/README.md | 0 .../examples}/example-playbook.yml | 0 {examples => doc/examples}/example.kdbx | Bin {examples => doc/examples}/group_vars/all | 0 galaxy.yml | 64 ++++++++++++++++++ plugins/README.md | 31 +++++++++ keepass.py => plugins/lookup/keepass.py | 0 7 files changed, 95 insertions(+) rename {examples => doc/examples}/README.md (100%) rename {examples => doc/examples}/example-playbook.yml (100%) rename {examples => doc/examples}/example.kdbx (100%) rename {examples => doc/examples}/group_vars/all (100%) create mode 100644 galaxy.yml create mode 100644 plugins/README.md rename keepass.py => plugins/lookup/keepass.py (100%) diff --git a/examples/README.md b/doc/examples/README.md similarity index 100% rename from examples/README.md rename to doc/examples/README.md diff --git a/examples/example-playbook.yml b/doc/examples/example-playbook.yml similarity index 100% rename from examples/example-playbook.yml rename to doc/examples/example-playbook.yml diff --git a/examples/example.kdbx b/doc/examples/example.kdbx similarity index 100% rename from examples/example.kdbx rename to doc/examples/example.kdbx diff --git a/examples/group_vars/all b/doc/examples/group_vars/all similarity index 100% rename from examples/group_vars/all rename to doc/examples/group_vars/all diff --git a/galaxy.yml b/galaxy.yml new file mode 100644 index 0000000..e7c55e9 --- /dev/null +++ b/galaxy.yml @@ -0,0 +1,64 @@ +### 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: viczem + +# The name of the collection. Has the same character restrictions as 'namespace' +name: keepass + +# 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: +- Victor Zemtsov + + +### OPTIONAL but strongly recommended +# A short summary description of the collection +description: The collection provides a lookup plugin that allow to read data from KeePass file. + +# 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: [] + +# 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: 'LICENSE' + +# 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: + - keepass + - lookup + - plugin + +# 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://github.com/viczem/ansible-keepass + +# The URL to any online docs +documentation: https://github.com/viczem/ansible-keepass/blob/main/doc + +# The URL to the homepage of the collection/project +homepage: https://github.com/viczem/ansible-keepass + +# The URL to the collection issue tracker +issues: https://github.com/viczem/ansible-keepass/issues + +# A list of file glob-like patterns used to filter any files or directories that should not be included in the build +# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This +# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry', +# and '.git' are always filtered +build_ignore: [] + diff --git a/plugins/README.md b/plugins/README.md new file mode 100644 index 0000000..775d977 --- /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-core/2.12/plugins/plugins.html). diff --git a/keepass.py b/plugins/lookup/keepass.py similarity index 100% rename from keepass.py rename to plugins/lookup/keepass.py From df3e6967023c339a6a29eb5322b139ee9fad2f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gon=C3=A7alves?= Date: Sat, 9 Jul 2022 18:20:50 +0200 Subject: [PATCH 2/3] Update documentation according to the collection previously created. --- README.md | 13 ++++++------- doc/examples/example-playbook.yml | 16 ++++++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 9a5f954..306dabb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ansible KeePass Lookup Plugin -The plugin allows to read data from KeePass file (modifying is not supported) +This collection provides a plugin that allows to read data from KeePass file (modifying is not supported) ## How it works @@ -15,8 +15,7 @@ The UNIX socket file is stored in a temporary folder according to OS. Requirements: `python 3`, `pykeepass==4.0.2` pip install 'pykeepass==4.0.2' --user - mkdir -p ~/.ansible/plugins/lookup && cd "$_" - curl https://raw.githubusercontent.com/viczem/ansible-keepass/main/keepass.py -o ./keepass.py + ansible-galaxy install viczem.keepass ## Variables @@ -44,8 +43,8 @@ Use `ansible-vault encrypt_string` to encrypt it and use it like below ### Example - ansible_user : "{{ lookup('keepass', 'path/to/entry', 'username') }}" - ansible_become_pass : "{{ lookup('keepass', 'path/to/entry', 'password') }}" - ansible_custom_field : "{{ lookup('keepass', 'path/to/entry', 'custom_properties', 'a_custom_property_name') }}" + ansible_user : "{{ lookup('viczem.keepass.keepass', 'path/to/entry', 'username') }}" + ansible_become_pass : "{{ lookup('viczem.keepass.keepass', 'path/to/entry', 'password') }}" + ansible_custom_field : "{{ lookup('viczem.keepass.keepass', 'path/to/entry', 'custom_properties', 'a_custom_property_name') }}" -More examples see in [/examples](/examples). \ No newline at end of file +More examples see in [/doc/examples](/doc/examples). diff --git a/doc/examples/example-playbook.yml b/doc/examples/example-playbook.yml index 4e44bc5..1af582f 100644 --- a/doc/examples/example-playbook.yml +++ b/doc/examples/example-playbook.yml @@ -3,13 +3,13 @@ hosts: 127.0.0.1 connection: local vars: - spam_login: "{{ lookup('keepass', 'spam', 'username') }}" - spam_password: "{{ lookup('keepass', 'spam', 'password') }}" - ham_login: "{{ lookup('keepass', 'example/ham', 'username') }}" - ham_password: "{{ lookup('keepass', 'example/ham', 'password') }}" - slash_login: "{{ lookup('keepass', 'slash\\/group/slash\\/title', 'username') }}" - slash_url: "{{ lookup('keepass', 'slash\\/group/slash\\/title', 'url') }}" - pork_custom_property: "{{ lookup('keepass', 'example/pork', 'custom_properties', 'pork_custom_property')}}" + spam_login: "{{ lookup('viczem.keepass.keepass', 'spam', 'username') }}" + spam_password: "{{ lookup('viczem.keepass.keepass', 'spam', 'password') }}" + ham_login: "{{ lookup('viczem.keepass.keepass', 'example/ham', 'username') }}" + ham_password: "{{ lookup('viczem.keepass.keepass', 'example/ham', 'password') }}" + slash_login: "{{ lookup('viczem.keepass.keepass', 'slash\\/group/slash\\/title', 'username') }}" + slash_url: "{{ lookup('viczem.keepass.keepass', 'slash\\/group/slash\\/title', 'url') }}" + pork_custom_property: "{{ lookup('viczem.keepass.keepass', 'example/pork', 'custom_properties', 'pork_custom_property')}}" tasks: @@ -29,4 +29,4 @@ - debug: msg: "fetch entry: '/slash\\/group/slash\\/title'; username: '{{ slash_login }}'; url: '{{ slash_url }}'" - - debug: "{{ lookup('keepass', 'close') }}" \ No newline at end of file + - debug: "{{ lookup('viczem.keepass.keepass', 'close') }}" From afe4bff556ad32b241f47633fa299c898fff056e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gon=C3=A7alves?= Date: Sat, 9 Jul 2022 19:10:05 +0200 Subject: [PATCH 3/3] Fix galaxy version --- galaxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.yml b/galaxy.yml index e7c55e9..d2e4078 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: viczem name: keepass # The version of the collection. Must be compatible with semantic versioning -version: 1.0.0 +version: 0.5.0 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md