diff --git a/lib/ansible/plugins/filter/network.py b/lib/ansible/plugins/filter/network.py index 3f266fa5bfb..bf7711d0fa9 100644 --- a/lib/ansible/plugins/filter/network.py +++ b/lib/ansible/plugins/filter/network.py @@ -33,7 +33,7 @@ from ansible.module_utils.six import iteritems, string_types from ansible.module_utils.common._collections_compat import Mapping from ansible.errors import AnsibleError, AnsibleFilterError from ansible.utils.display import Display -from ansible.utils.encrypt import random_password +from ansible.utils.encrypt import passlib_or_crypt, random_password try: import yaml @@ -47,12 +47,6 @@ try: except ImportError: HAS_TEXTFSM = False -try: - from passlib.hash import md5_crypt - HAS_PASSLIB = True -except ImportError: - HAS_PASSLIB = False - display = Display() @@ -357,9 +351,6 @@ def parse_xml(output, tmpl): def type5_pw(password, salt=None): - if not HAS_PASSLIB: - raise AnsibleFilterError('type5_pw filter requires PassLib library to be installed') - if not isinstance(password, string_types): raise AnsibleFilterError("type5_pw password input should be a string, but was given a input of %s" % (type(password).__name__)) @@ -375,7 +366,7 @@ def type5_pw(password, salt=None): elif not set(salt) <= set(salt_chars): raise AnsibleFilterError("type5_pw salt used inproper characters, must be one of %s" % (salt_chars)) - encrypted_password = md5_crypt.encrypt(password, salt=salt) + encrypted_password = passlib_or_crypt(password, "md5_crypt", salt=salt) return encrypted_password diff --git a/test/units/plugins/filter/test_network.py b/test/units/plugins/filter/test_network.py index 8f135ab9df9..cbce8c823fa 100644 --- a/test/units/plugins/filter/test_network.py +++ b/test/units/plugins/filter/test_network.py @@ -23,8 +23,7 @@ import sys import pytest from units.compat import unittest -from ansible.plugins.filter.network import (HAS_PASSLIB, parse_xml, type5_pw, hash_salt, - comp_type5, vlan_parser) +from ansible.plugins.filter.network import parse_xml, type5_pw, hash_salt, comp_type5, vlan_parser fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'network') @@ -83,7 +82,6 @@ class TestNetworkParseFilter(unittest.TestCase): self.assertEqual("parse_xml works on string input, but given input of : %s" % type(output), str(e.exception)) -@pytest.mark.skipif(not HAS_PASSLIB, reason="Current type5_pw filter needs passlib to function") class TestNetworkType5(unittest.TestCase): def test_defined_salt_success(self): @@ -147,7 +145,6 @@ class TestHashSalt(unittest.TestCase): self.assertEqual("Could not parse salt out password correctly from $nTc1$Z28sUTcWfXlvVe2x.3XAa.", str(e.exception)) -@pytest.mark.skipif(not HAS_PASSLIB, reason="Current comp_type5 filter needs passlib to function") class TestCompareType5(unittest.TestCase): def test_compare_type5_boolean(self):