basic.py: catch ValueError when trying to import hash algorithms (#44551)

* basic.py: catch more Exceptions when trying to import md5 hash algorithms
pull/44558/head
Jordan Borean 6 years ago committed by Toshio Kuratomi
parent c8ee383783
commit e07352b9de

@ -0,0 +1,2 @@
bugfixes:
- basic.py - catch ValueError in case a FIPS enabled platform raises this exception - https://github.com/ansible/ansible/issues/44447

@ -132,13 +132,19 @@ try:
algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
for algorithm in algorithms: for algorithm in algorithms:
AVAILABLE_HASH_ALGORITHMS[algorithm] = getattr(hashlib, algorithm) AVAILABLE_HASH_ALGORITHMS[algorithm] = getattr(hashlib, algorithm)
except ImportError:
# we may have been able to import md5 but it could still not be available
try:
hashlib.md5()
except ValueError:
algorithms.pop('md5', None)
except Exception:
import sha import sha
AVAILABLE_HASH_ALGORITHMS = {'sha1': sha.sha} AVAILABLE_HASH_ALGORITHMS = {'sha1': sha.sha}
try: try:
import md5 import md5
AVAILABLE_HASH_ALGORITHMS['md5'] = md5.md5 AVAILABLE_HASH_ALGORITHMS['md5'] = md5.md5
except ImportError: except Exception:
pass pass
from ansible.module_utils.common._collections_compat import ( from ansible.module_utils.common._collections_compat import (

Loading…
Cancel
Save