From 692bfa872a0f90de08fa4852963d5ad1998bc79b Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 18 Oct 2016 19:50:45 +0100 Subject: [PATCH] Make bcrypt + passlib work in password_hash filter If hashtype for the password_hash filter is 'blowfish' and passlib is available, hashing fails as the hash function for this is named 'bcrypt' (and not 'blowfish_crypt'). Special case this so that the correct function is called. --- lib/ansible/plugins/filter/core.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index 276a95dd160..81463ce0e34 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -257,7 +257,11 @@ def get_encrypted_password(password, hashtype='sha512', salt=None): saltstring = "$%s$%s" % (cryptmethod[hashtype],salt) encrypted = crypt.crypt(password, saltstring) else: - cls = getattr(passlib.hash, '%s_crypt' % hashtype) + if hashtype == 'blowfish': + cls = passlib.hash.bcrypt; + else: + cls = getattr(passlib.hash, '%s_crypt' % hashtype) + encrypted = cls.encrypt(password, salt=salt) return encrypted