### Summary

When I use a core filter like `to_yaml`, then `plugins/filter/core.py` calls `import crypt`, which tries to load MD5 methods. In a FIPS-enabled system, this leads to an "operation not permitted" error.



### Issue Type

Bug Report

### Component Name

ansible

### Ansible Version

```console
ansible --version
ansible 2.10.8
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.4 (default, Apr 14 2021, 12:55:12) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
```


### Configuration

```console
$ ansible-config dump --only-changed
# there are no changes from the default
```


### OS / Environment

RHEL 7 host running image centos:7 on containerd

```shell 
% openssl version
OpenSSL 1.0.2t-fips  10 Sep 2019
```

```shell
% pip show cryptography
Name: cryptography
Version: 3.0
Summary: cryptography is a package which provides cryptographic recipes and primitives to Python developers.
Home-page: https://github.com/pyca/cryptography
Author: The cryptography developers
Author-email: cryptography-dev@python.org
License: BSD or Apache License, Version 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: cffi, six
Required-by: ansible-base
```

### Steps to Reproduce


```yaml (paste below)
# try_fips.yml
- name: test fips
  gather_facts: no
  hosts: localhost
  connection: local

  vars:
    a:
      b: 1
      c: 2

  tasks:
    - debug:
        msg: "{{ a | to_yaml }}"
```

```shell 
ansible-playbook -vvv try_fips.yml

ansible-playbook 2.10.8
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.9.4 (default, Apr 14 2021, 12:55:12) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
No config file found; using defaults
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: prove_fips.yml *************************************************************************************************************************************************************
1 plays in /support/scripts/prove_fips.yml

PLAY [test fips] *********************************************************************************************************************************************************************
META: ran handlers

TASK [debug] *************************************************************************************************************************************************************************
task path: /support/scripts/prove_fips.yml:12
[WARNING]: Skipping plugin (/usr/local/lib/python3.9/site-packages/ansible/plugins/filter/core.py) as it seems to be invalid: [Errno 1] Operation not permitted
[WARNING]: an unexpected error occurred during Jinja2 environment setup: [Errno 1] Operation not permitted   line 0
exception during Jinja2 environment setup: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 504, in __getitem__
    plugin_impl = self._pluginloader.get(module_name)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 993, in get
    return super(Jinja2Loader, self).get(name, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 792, in get
    return self.get_with_context(name, *args, **kwargs).object
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 812, in get_with_context
    self._module_cache[path] = self._load_module_source(name, path)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 776, in _load_module_source
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/filter/core.py", line 23, in <module>
    import crypt
  File "/usr/local/lib/python3.9/crypt.py", line 117, in <module>
    _add_method('MD5', '1', 8, 34)
  File "/usr/local/lib/python3.9/crypt.py", line 94, in _add_method
    result = crypt('', salt)
"""Wrapper to the POSIX crypt library call and associated functionality."""

import sys as _sys

try:
    import _crypt
except ModuleNotFoundError:
    if _sys.platform == 'win32':
        raise ImportError("The crypt module is not supported on Windows")
    else:
        raise ImportError("The required _crypt module was not built as part of CPython")

import errno
import string as _string
from random import SystemRandom as _SystemRandom
from collections import namedtuple as _namedtuple


_saltchars = _string.ascii_letters + _string.digits + './'
_sr = _SystemRandom()


class _Method(_namedtuple('_Method', 'name ident salt_chars total_size')):

    """Class representing a salt method per the Modular Crypt Format or the
    legacy 2-character crypt method."""

    def __repr__(self):
        return '<crypt.METHOD_{}>'.format(self.name)


def mksalt(method=None, *, rounds=None):
    """Generate a salt for the specified method.

    If not specified, the strongest available method will be used.

    """
    if method is None:
        method = methods[0]
    if rounds is not None and not isinstance(rounds, int):
        raise TypeError(f'{rounds.__class__.__name__} object cannot be '
                        f'interpreted as an integer')
    if not method.ident:  # traditional
        s = ''
    else:  # modular
        s = f'${method.ident}$'

    if method.ident and method.ident[0] == '2':  # Blowfish variants
        if rounds is None:
"/usr/local/lib/python3.9/crypt.py" 120L, 3819C
    prepended.
  File "/usr/local/lib/python3.9/crypt.py", line 82, in crypt
    return _crypt.crypt(word, salt)
PermissionError: [Errno 1] Operation not permitted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 506, in __getitem__
    raise TemplateSyntaxError(to_native(e), 0)
jinja2.exceptions.TemplateSyntaxError: [Errno 1] Operation not permitted
  line 0
exception during Jinja2 environment setup: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 504, in __getitem__
    plugin_impl = self._pluginloader.get(module_name)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 993, in get
    return super(Jinja2Loader, self).get(name, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 792, in get
    return self.get_with_context(name, *args, **kwargs).object
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 812, in get_with_context
    self._module_cache[path] = self._load_module_source(name, path)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 776, in _load_module_source
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/filter/core.py", line 23, in <module>
    import crypt
  File "/usr/local/lib/python3.9/crypt.py", line 117, in <module>
    _add_method('MD5', '1', 8, 34)
  File "/usr/local/lib/python3.9/crypt.py", line 94, in _add_method
    result = crypt('', salt)
  File "/usr/local/lib/python3.9/crypt.py", line 82, in crypt
    return _crypt.crypt(word, salt)
PermissionError: [Errno 1] Operation not permitted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 506, in __getitem__
    raise TemplateSyntaxError(to_native(e), 0)
jinja2.exceptions.TemplateSyntaxError: [Errno 1] Operation not permitted
  line 0
fatal: [localhost]: FAILED! => {
    "msg": "template error while templating string: [Errno 1] Operation not permitted\n  line 0. String: {{ a | to_yaml }}"
}

PLAY RECAP ***************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

```

### Expected Results

I expected ansible to dump the simple data structure to yaml. This works if I comment out the `_add_method('MD5'...)` and `_add_method('CRYPT'...)` lines in `/usr/local/lib/python3.9/crypt.py`:

```
TASK [debug] *************************************************************************************************************************************************************************
task path: /support/scripts/prove_fips.yml:12
ok: [localhost] => {
    "msg": "{b: 1, c: 2}\n"
}
META: ran handlers
META: ran handlers

PLAY RECAP ***************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
```


### Actual Results

```console
ansible-playbook -vvv /support/scripts/prove_fips.yml
ansible-playbook 2.10.8
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.9.4 (default, Apr 14 2021, 12:55:12) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
No config file found; using defaults
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: prove_fips.yml *************************************************************************************************************************************************************
1 plays in /support/scripts/prove_fips.yml

PLAY [test fips] *********************************************************************************************************************************************************************
META: ran handlers

TASK [debug] *************************************************************************************************************************************************************************
task path: /support/scripts/prove_fips.yml:12
[WARNING]: Skipping plugin (/usr/local/lib/python3.9/site-packages/ansible/plugins/filter/core.py) as it seems to be invalid: [Errno 1] Operation not permitted
[WARNING]: an unexpected error occurred during Jinja2 environment setup: [Errno 1] Operation not permitted   line 0
exception during Jinja2 environment setup: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 504, in __getitem__
    plugin_impl = self._pluginloader.get(module_name)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 993, in get
    return super(Jinja2Loader, self).get(name, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 792, in get
    return self.get_with_context(name, *args, **kwargs).object
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 812, in get_with_context
    self._module_cache[path] = self._load_module_source(name, path)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 776, in _load_module_source
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/filter/core.py", line 23, in <module>
    import crypt
  File "/usr/local/lib/python3.9/crypt.py", line 117, in <module>
    _add_method('MD5', '1', 8, 34)
  File "/usr/local/lib/python3.9/crypt.py", line 94, in _add_method
    result = crypt('', salt)
"""Wrapper to the POSIX crypt library call and associated functionality."""

import sys as _sys

try:
    import _crypt
except ModuleNotFoundError:
    if _sys.platform == 'win32':
        raise ImportError("The crypt module is not supported on Windows")
    else:
        raise ImportError("The required _crypt module was not built as part of CPython")

import errno
import string as _string
from random import SystemRandom as _SystemRandom
from collections import namedtuple as _namedtuple


_saltchars = _string.ascii_letters + _string.digits + './'
_sr = _SystemRandom()


class _Method(_namedtuple('_Method', 'name ident salt_chars total_size')):

    """Class representing a salt method per the Modular Crypt Format or the
    legacy 2-character crypt method."""

    def __repr__(self):
        return '<crypt.METHOD_{}>'.format(self.name)


def mksalt(method=None, *, rounds=None):
    """Generate a salt for the specified method.

    If not specified, the strongest available method will be used.

    """
    if method is None:
        method = methods[0]
    if rounds is not None and not isinstance(rounds, int):
        raise TypeError(f'{rounds.__class__.__name__} object cannot be '
                        f'interpreted as an integer')
    if not method.ident:  # traditional
        s = ''
    else:  # modular
        s = f'${method.ident}$'

    if method.ident and method.ident[0] == '2':  # Blowfish variants
        if rounds is None:
"/usr/local/lib/python3.9/crypt.py" 120L, 3819C
    prepended.
  File "/usr/local/lib/python3.9/crypt.py", line 82, in crypt
    return _crypt.crypt(word, salt)
PermissionError: [Errno 1] Operation not permitted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 506, in __getitem__
    raise TemplateSyntaxError(to_native(e), 0)
jinja2.exceptions.TemplateSyntaxError: [Errno 1] Operation not permitted
  line 0
exception during Jinja2 environment setup: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 504, in __getitem__
    plugin_impl = self._pluginloader.get(module_name)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 993, in get
    return super(Jinja2Loader, self).get(name, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 792, in get
    return self.get_with_context(name, *args, **kwargs).object
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 812, in get_with_context
    self._module_cache[path] = self._load_module_source(name, path)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 776, in _load_module_source
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/filter/core.py", line 23, in <module>
    import crypt
  File "/usr/local/lib/python3.9/crypt.py", line 117, in <module>
    _add_method('MD5', '1', 8, 34)
  File "/usr/local/lib/python3.9/crypt.py", line 94, in _add_method
    result = crypt('', salt)
  File "/usr/local/lib/python3.9/crypt.py", line 82, in crypt
    return _crypt.crypt(word, salt)
PermissionError: [Errno 1] Operation not permitted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 506, in __getitem__
    raise TemplateSyntaxError(to_native(e), 0)
jinja2.exceptions.TemplateSyntaxError: [Errno 1] Operation not permitted
  line 0
fatal: [localhost]: FAILED! => {


    "msg": "template error while templating string: [Errno 1] Operation not permitted\n  line 0. String: {{ a | to_yaml }}"
}

PLAY RECAP ***************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
```


### Code of Conduct

I agree to follow the Ansible Code of Conduct
if PASSLIB_AVAILABLE:
        return PasslibHash(algorithm).hash(secret, salt=salt, salt_size=salt_size, rounds=rounds)
    else:
        return CryptHash(algorithm).hash(secret, salt=salt, salt_size=salt_size, rounds=rounds)
def do_encrypt(result, encrypt, salt_size=None, salt=None):
    return passlib_or_crypt(result, encrypt, salt_size=salt_size, salt=salt)