Code Monkey home page Code Monkey logo

ansible-keepass's Introduction

Ansible KeePass Lookup Plugin

This collection provides plugins that allows to read data from KeePass file (modifying is not supported)

How it works

The lookup plugin opens a UNIX socket with decrypted KeePass file. For performance reasons, decryption occurs only once at socket startup, and the KeePass file remains decrypted as long as the socket is open. The UNIX socket file is stored in a temporary folder according to OS.

Installation

Requirements: python 3, pykeepass==4.0.3

pip install 'pykeepass==4.0.3' --user
ansible-galaxy collection install viczem.keepass

Variables

  • keepass_dbx - path to KeePass file
  • keepass_psw - Optional. Password (required if keepass_key is not set)
  • keepass_key - Optional. Path to keyfile (required if keepass_psw is not set)
  • keepass_ttl - Optional. Socket TTL (will be closed automatically when not used). Default 60 seconds.

Environment Variables

If you want to use ansible-keepass with continuous integration, it could be helpful not to use ansible variables but Shell environment variables.

  • ANSIBLE_KEEPASS_PSW Password
  • ANSIBLE_KEEPASS_KEY Path to keyfile
  • ANSIBLE_KEEPASS_TTL Socket TTL
  • ANSIBLE_KEEPASS_SOCKET Path to Keepass Socket

The environment variables will only be used, if no ansible variable is set.

You can than start the socket in another background process like this

export ANSIBLE_KEEPASS_PSW=mySecret
export ANSIBLE_KEEPASS_SOCKET=/home/build/.my-ansible-sock.${CI_JOB_ID}
export ANSIBLE_TTL=600 # 10 Minutes
/home/build/ansible-pyenv/bin/python3 /home/build/.ansible/roles/ansible_collections/viczem/keepass/plugins/lookup/keepass.py /path-to/my-keepass.kdbx &
ansible-playbook -v playbook1.yml
ansible-playbook -v playbook2.yml

Usage

ansible-doc -t lookup keepass to get description of the plugin

WARNING: For security reasons, do not store KeePass passwords in plain text. Use ansible-vault encrypt_string to encrypt it and use it like below

# file: group_vars/all

keepass_dbx: "~/.keepass/database.kdbx"
keepass_psw: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        ...encrypted password...

Examples

More examples see in /docs/examples.

Lookup

ansible_user        : "{{ lookup('viczem.keepass.keepass', 'path/to/entry', 'username') }}"
ansible_become_pass : "{{ lookup('viczem.keepass.keepass', 'path/to/entry', 'password') }}"
custom_field        : "{{ lookup('viczem.keepass.keepass', 'path/to/entry', 'custom_properties', 'a_custom_property_name') }}"
attachment          : "{{ lookup('viczem.keepass.keepass', 'path/to/entry', 'attachments', 'a_file_name') }}"

Module

- name: "Export file: attachment.txt"
  viczem.keepass.attachment:
    database: "{{ keepass_dbx }}"
    password: "{{ keepass_psw }}"
    entrypath: example/attachments
    attachment: "attachment.txt"
    dest: "{{ keepass_attachment_1_name }}"

Contributing

See /docs/contributing.

ansible-keepass's People

Contributors

viczem avatar dangoncalves avatar hefee avatar jimisola avatar kism avatar scaleuptechnologies avatar callum17 avatar jpmens avatar tisoft avatar nitram2342 avatar michaelellnebrand avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.