Ansible cannot pickle 'module' object
I had the same issue today, my install details:
$ ansible --version
ansible 2.9.0
config file = None
configured module search path = ['/Users/mark/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/mark/.pyvenv/ansible/lib/python3.9/site-packages/ansible
executable location = /Users/mark/.pyvenv/ansible/bin/ansible
python version = 3.9.6 (default, Jun 29 2021, 05:25:02) [Clang 12.0.5 (clang-1205.0.22.9)]
$ ansible app -m ping
ERROR! Unexpected Exception, this is probably a bug: cannot pickle 'module' object
to see the full traceback, use -vvv
I was unable to resolve with Python3, but using a virtual environment for Python2 it did work:
$ ansible --version
/Users/mark/.pyenv/py2ansible/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:41: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
from cryptography.exceptions import InvalidSignature
ansible 2.9.0
config file = None
configured module search path = [u'/Users/mark/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Users/mark/.pyenv/py2ansible/lib/python2.7/site-packages/ansible
executable location = /Users/mark/.pyenv/py2ansible/bin/ansible
python version = 2.7.16 (default, May 8 2021, 11:48:02) [GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy
$ ansible app -m ping
/Users/mark/.pyenv/py2ansible/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:41: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
from cryptography.exceptions import InvalidSignature
m1-base | SUCCESS => {
"changed": false,
"ping": "pong"
}
Maybe not ideal, but at least I can carry on. If you did manage to solve, please post your solution
To create the virtual env on MacBookPro:
pip install virtualenv
python -m virtualenv ~/.pyenv/py2ansible
source ~/.pyenv/py2ansible/bin/activate