Skip to content

Instantly share code, notes, and snippets.

@glaszig
Created August 12, 2015 22:52
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glaszig/1ba07d81d010b653f92d to your computer and use it in GitHub Desktop.
Save glaszig/1ba07d81d010b653f92d to your computer and use it in GitHub Desktop.
ansible passlib filter plugin
# this ansible/jinja2 filter plugin allows you to use passlib's *_crypt functions
# until ansible 2.0 comes out - see https://github.com/ansible/ansible/issues/11244.
#
# this filter depends on passlib being installed:
# $ pip install passlib
#
# put this into your playbook's `filter_plugins` folder.
#
# usage example:
# - name: create user
# user:
# name: username
# password: "{{ user_password | passlib_hash('sha512', user_salt) }}"
from ansible import errors
try:
import passlib
except Exception, e:
raise errors.AnsibleFilterError('passlib package is not installed')
def passlib_hash(pw, alg = 'sha512', salt = None, rounds = None, implicit_rounds = None, relaxed = None):
return crypt_method(alg).encrypt(pw, salt = salt, rounds = rounds, implicit_rounds = implicit_rounds, relaxed = relaxed)
def crypt_method(alg):
return getattr(passlib.hash, alg + '_crypt')
class FilterModule(object):
def filters(self):
return {
'passlib_hash' : passlib_hash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment