Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation der docker Dienste schlägt fehl wenn das Python docker-compose Modul fehlt #4

Open
rogue73 opened this issue Jan 13, 2024 · 6 comments

Comments

@rogue73
Copy link

rogue73 commented Jan 13, 2024

Starten der Dienste schlägt fehl da compose nicht funktioniert

Ich bekomme beim ausführen der Playbooks um die Dienste zu installieren und zu starten immer einen docker-compose Fehler.

TASK [start compose service] ***************************************************************************************************************************************************************
fatal: [server]: FAILED! => {"changed": false, "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: Traceback (most recent call last):\n  File \"/tmp/ansible_community.docker.docker_compose_payload_9jbhvt3_/ansible_community.docker.docker_compose_payload.zip/ansible_collections/community/docker/plugins/modules/docker_compose.py\", line 522, in <module>\nModuleNotFoundError: No module named 'compose'\n"}


Hier fehlt auf dem Zielserver das PyPi Modul docker-compose.

Ich habe dazu die system Role im Task main.yml direkt nach der Installation der apt Pakete um:

- name: install pip docker-compose
  pip:
    name: docker-compose>=1.29.2


erweitert um das Python docker-compose mit pip zu installieren.

@dm2002
Copy link

dm2002 commented Jan 13, 2024

Ich hatte den gleichen Fehler, allerdings kann ich das Paket mit dem genannten Command nicht nachinstallieren, weil das Environment extern gemanaged sein soll..

TASK [system : install pip docker-compose] ******************************************************************************************************************************************** fatal: [xx]: FAILED! => {"changed": false, "cmd": ["/usr/bin/python3", "-m", "pip.__main__", "install", "docker-compose>=1.29.2"], "msg": "\n:stderr: error: externally-managed-environment\n\n× This environment is externally managed\n╰─> To install Python packages system-wide, try apt install\n python3-xyz, where xyz is the package you are trying to\n install.\n \n If you wish to install a non-Debian-packaged Python package,\n create a virtual environment using python3 -m venv path/to/venv.\n Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make\n sure you have python3-full installed.\n \n If you wish to install a non-Debian packaged Python application,\n it may be easiest to use pipx install xyz, which will manage a\n virtual environment for you. Make sure you have pipx installed.\n \n See /usr/share/doc/python3.11/README.venv for more information.\n\nnote: 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.\nhint: See PEP 668 for the detailed specification.\n"}

@dm2002
Copy link

dm2002 commented Jan 13, 2024

Den externally-managed-environment Fehler konnte ich lösen durch:
sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED

Danach gab es beim Installieren von docker-compose aber weitere Fehler, irgendwelche Abhängigkeiten zu PyYaml scheinen nicht mehr zu funktionieren. Ich vermute das ist ein Problem spezifisch mit meinem Debian 12:
Collecting pyyaml==5.4
AttributeError: cython_sources
Der Fehler ist hier beschrieben.

Er lies sich durch folgende Commands lösen:
pip install "cython<3.0.0" wheel; pip install "pyyaml==5.4.1" --no-build-isolation; pip install docker-compose

@diankov
Copy link

diankov commented Feb 29, 2024

- name: install pip docker-compose
  pip:
    name: docker-compose>=1.29.2

Das hat bei mir funktioniert. Aber warum wird docker-compose gefordert? Könnte man nicht den vorhandenen Docker Compose nutzen?

@Jofagi
Copy link

Jofagi commented Mar 3, 2024

docker-compose wird anscheinend von dem ansible-galaxy docker plugin benutzt. Damit ist das nicht direkt beeinflussbar. Ich sehe zumindest keinen Weg, "docker compose" statt "docker-compose" ausführen zu lassen.
Was aber besser zu funktionieren scheint, statt compose mit pip zu installieren, ist es mit apt zu tun. Dann bekommt man auch keinen "EXTERNALLY MANAGED" Fehler.

Meine Lösung: docker-compose zur liste der basic_packages hinzufügen.

# roles/sysem/vars/main.yml
basic_packages:
# ...
  - docker-compose

@AndreasCS
Copy link

Es gibt eine Lösung für dieses Problem:
Verwendung des Ansible Moduls "community.docker.docker_compose_v2“ (https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_v2_module.html). Das empfiehlt mehr oder weniger indirekt auch docker selbst (https://docs.docker.com/compose/migrate/).
Die Anpassungen sind hierbei relativ geringfügig:
In der Datei "roles/compose_hull/tasks/deploy_docker.yml" entfallen beim Task ".. docker compose .." die Parameter "restarted" und "stopped" (die gibt es so nicht mehr, der Parameter "state" bietet jetzt diese Zustände alleine an).
In der Datei "roles/compose_hull/defaults/main.yml" bei "docker_compose_params" ändert man den Parameter "recreate" in "auto".
Bei mir hat es so mit Debian 12 als Ziel ohne weitere Klimmzüge funktioniert.

@d33c0n
Copy link

d33c0n commented Apr 30, 2024

danke @AndreasCS, das hat bei mir funktioniert. Ich musste nur in der Datei "roles/compose_hull/tasks/deploy_docker.yml" beim Task ".. docker compose .." auch den collection name ändern in community.docker.docker_compose_v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants