Issues with Ansible Crypto on MacOS

Posted on Dec 28, 2021

For some reason, I started getting this error message when trying to use Ansible on my Apple M1 machine. I probably caused this issue at some point, either by upgrading to macOS 12.1 Monterey, or by doing something with homebrew1. I guess.

  $ ansible-playbook playbooks/nameserver.yml
  ERROR! Unexpected Exception, this is probably a bug: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-39-darwin.so', Cannot load '_raw_ecb.abi3.so': dlopen(/opt/homebrew/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so, 0x0006): tried: '/opt/homebrew/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_raw_ecb.abi3.so' (no such file), '/usr/lib/_raw_ecb.abi3.so' (no such file), '/opt/homebrew/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_raw_ecb.abi3.so' (no such file), '/usr/lib/_raw_ecb.abi3.so' (no such file), Not found '_raw_ecb.so'
  the full traceback was:

  Traceback (most recent call last):
    File "/opt/homebrew/bin/ansible-playbook", line 104, in <module>
      mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
    File "/opt/homebrew/lib/python3.9/site-packages/ansible/cli/__init__.py", line 21, in <module>
      from ansible.inventory.manager import InventoryManager
    File "/opt/homebrew/lib/python3.9/site-packages/ansible/inventory/manager.py", line 38, in <module>
      from ansible.plugins.loader import inventory_loader
    File "/opt/homebrew/lib/python3.9/site-packages/ansible/plugins/loader.py", line 23, in <module>
      from ansible.parsing.utils.yaml import from_yaml
    File "/opt/homebrew/lib/python3.9/site-packages/ansible/parsing/utils/yaml.py", line 17, in <module>
      from ansible.parsing.yaml.loader import AnsibleLoader
    File "/opt/homebrew/lib/python3.9/site-packages/ansible/parsing/yaml/loader.py", line 30, in <module>
      from ansible.parsing.yaml.constructor import AnsibleConstructor
    File "/opt/homebrew/lib/python3.9/site-packages/ansible/parsing/yaml/constructor.py", line 28, in <module>
      from ansible.parsing.vault import VaultLib
    File "/opt/homebrew/lib/python3.9/site-packages/ansible/parsing/vault/__init__.py", line 58, in <module>
      from Crypto.Cipher import AES as AES_pycrypto
    File "/opt/homebrew/lib/python3.9/site-packages/Crypto/Cipher/__init__.py", line 27, in <module>
      from Crypto.Cipher._mode_ecb import _create_ecb_cipher
    File "/opt/homebrew/lib/python3.9/site-packages/Crypto/Cipher/_mode_ecb.py", line 35, in <module>
      raw_ecb_lib = load_pycryptodome_raw_lib("Crypto.Cipher._raw_ecb", """
    File "/opt/homebrew/lib/python3.9/site-packages/Crypto/Util/_raw_api.py", line 309, in load_pycryptodome_raw_lib
      raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
  OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-39-darwin.so', Cannot load '_raw_ecb.abi3.so': dlopen(/opt/homebrew/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so, 0x0006): tried: '/opt/homebrew/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_raw_ecb.abi3.so' (no such file), '/usr/lib/_raw_ecb.abi3.so' (no such file), '/opt/homebrew/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_raw_ecb.abi3.so' (no such file), '/usr/lib/_raw_ecb.abi3.so' (no such file), Not found '_raw_ecb.so'

It proved to be hard to google and get anything relevant, so I thought I should write my hacky solution down.

  $ arch -arm64 brew link --overwrite ansible

I just reinstalled ansible…

Footnotes


1

Time to switch to Nix, I know…