Zum Inhalt

Ansible - ERROR No module named 'markupsafe'

Seit ein paar Tagen bekomme ich beim Ausführen von Ansible auf meinem MacBook den Fehler ERROR No module named markupsafe. Das Starten von Playbooks ist nicht mehr möglich und die Administration meiner Server kann nicht mehr automatisiert durchgeführt werden.

Fehlermeldung

Ansible bricht sofort nach dem Starten ab und meldet einen Fehler mit markupsafe.

ansible-playbook -i inventory.ini playbook.yml --ask-vault-pass                                              ─╯
ERROR: No module named 'markupsafe'

Ist markupsafe über haupt auf dem MacBook installiert?
Eine Abfrage mit dem Pythonbefehl ergab:

python3.12 -m pip show markupsafe                                                                                  ─╯
DEPRECATION: Loading egg at /opt/homebrew/Cellar/gpgme/1.23.1_1/lib/python3.12/site-packages/gpg-1.23.1-py3.12-macosx-14-arm64.egg is deprecated. pip 23.3 will enforce this behaviour change. A possible replacement is to use pip for package installation..
WARNING: Package(s) not found: markupsafe

Die Meldung besagt, dass das installierte markupsafe Paket veraltet sei und eine Installation via pip empfohlen wird.

Die De-Installation des Pakets per pip funktioniert eigentlich über den Befehl:

python3.12 -m pip uninstall markupsafe

Das Problem dabei ist aber, dass es sich um ein sog. externally-managed-environment Umgebung handelt. Die ganze Fehlermeldung lautet:

 python3.12 -m pip uninstall markupsafe                                                                             ─╯
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.

    If you wish to install a non-brew-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.

    If you wish to install a non-brew packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

Da ich alle Pakete bei meinem MacBook über Homebrew installiere und verwalte, könnte das die Ursache sein.

Kurzer Check bei 👉 https://formulae.brew.sh und siehe da, es gibt ein offizielles Brew für python-markupsafe.

Die verlinkte Seite ist die offizielle Projektseite von MarkupSafe 👉 https://palletsprojects.com/.

Die Lösung

Die Installation von MarkupSafe via Homebrew anstoßen:

brew install python-markupsafe                                                                                     ─╯
==> Downloading https://formulae.brew.sh/api/formula.jws.json
################################################################################################################# 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
################################################################################################################# 100.0%
Warning: python-markupsafe 2.1.3 is already installed and up-to-date.
To reinstall 2.1.3, run:
  brew reinstall python-markupsafe

Das Paket ist bereits installiert, erzeugt aber den Fehler. Deshalb einfach mal einen reinstall durchführen.

brew reinstall python-markupsafe

Nach der erneuten Installation versuchen wird unser Ansible Playbook zu starten und siehe da, der Fehler ist weg:

 ansible-playbook -i inventory.ini update_upgrade.yml --ask-vault-pass                                              ─╯
Vault password:

Ansible funktioniert und die Server lassen sich wieder automatisiert verwalten.

Gib mir gerne einen Kaffee ☕ aus ❗️

Wenn dir meine Beiträge gefallen und geholfen haben, dann kannst du mir gerne einen Kaffee ☕️ ausgeben.

Donation via PayPalDonation via LiberaPay

Donation via Bitcoin
Bitcoin Address: bc1qfuz93hw2fhdvfuxf6mlxlk8zdadvnktppkzqzj

Source