No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

password_hash.py 769B

1234567891011121314151617181920212223242526
  1. from ansible.errors import AnsibleError, AnsibleUndefinedVariable
  2. from jinja2 import StrictUndefined
  3. __metaclass__ = type
  4. try:
  5. import passlib.hash
  6. HAS_LIB = True
  7. except ImportError:
  8. HAS_LIB = False
  9. def check_lib():
  10. if not HAS_LIB:
  11. raise AnsibleError('You need to install "passlib" prior to running '
  12. 'password_hash-based filters')
  13. def doveadm_pw_hash(password):
  14. check_lib()
  15. if type(password) is StrictUndefined:
  16. raise AnsibleUndefinedVariable('Please pass a string into this password_hash-based filter')
  17. return passlib.hash.sha512_crypt.encrypt(password, rounds=5000)
  18. class FilterModule(object):
  19. def filters(self):
  20. return {
  21. 'doveadm_pw_hash': doveadm_pw_hash,
  22. }