Skip to content

Commit

Permalink
Merge branch 'create_collection' of https://github.com/dangoncalves/a…
Browse files Browse the repository at this point in the history
…nsible-keepass into dangoncalves-create_collection
  • Loading branch information
viczem committed Aug 8, 2022
2 parents f7dbfab + afe4bff commit ad823aa
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 39 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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).
More examples see in [/doc/examples](/doc/examples).
File renamed without changes.
32 changes: 32 additions & 0 deletions doc/examples/example-playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: Example
hosts: 127.0.0.1
connection: local
vars:
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:
- debug:
msg: "fetch entry: '/spam'; username: '{{ spam_login }}'; password: '{{ spam_password }}'"

- debug:
msg: "fetch entry: '/examples/ham'; username: '{{ ham_login }}'; password: '{{ ham_password }}'"

- name: pause to emulate long time operation (greater than keepass_ttl)
pause:
seconds: 5

- debug:
msg: "fetch entry: '/examples/pork'; custom_properties: 'pork_custom_property' - '{{ pork_custom_property }}'"

- debug:
msg: "fetch entry: '/slash\\/group/slash\\/title'; username: '{{ slash_login }}'; url: '{{ slash_url }}'"

- debug: "{{ lookup('viczem.keepass.keepass', 'close') }}"
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions examples/example-playbook.yml

This file was deleted.

64 changes: 64 additions & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
@@ -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: 0.5.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 <email> (url)
# @nicks:irc/im.site#channel'
authors:
- Victor Zemtsov <viczem.dev@gmail.com>


### 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: []

31 changes: 31 additions & 0 deletions plugins/README.md
Original file line number Diff line number Diff line change
@@ -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).
File renamed without changes.

0 comments on commit ad823aa

Please sign in to comment.