Giter VIP home page Giter VIP logo

Comments (22)

sammervalgas avatar sammervalgas commented on July 20, 2024 12

I used the command bellow:

pip install docker-compose --force-reinstall --user

This solved my problem.
Tks.

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024 4

You could also remove that task and change this task:

- name: Pip install docker for Ansible's docker_login and docker_service modules
  pip:
    name: "docker"

You can change the name to be: ["docker", "docker-compose"] instead.

Maybe that's a reasonable compromise. One where this role would allow you to configure which pip packages to install, this way if you need compose, you add it, but it defaults to just docker.

I don't manage any containers with Ansible because I don't use Ansible to initiate deploying my web applications. I only use Ansible to get my machines to the point where everything can be ran, but then I use either git hooks or CI services to handle deploying the app, and this is where I set up things like stopping compose, rebuilding, pulling, etc. and bringing it all back up.

from ansible-docker.

obilodeau avatar obilodeau commented on July 20, 2024 2

Having the following before the docker_service task works as a workaround:

  tasks:
  - pip: name=docker-compose

To me, this workaround is simple enough so do what you prefer. UX could be better but ideally docker_service would make sure its deps are installed on its own. That's the real UX flaw in my opinion.

As a side note, I'm curious, if you are not using docker_service, what do you use to manage your compose with ansible?

from ansible-docker.

obilodeau avatar obilodeau commented on July 20, 2024 1

Role definition is just:

  roles:
  # Install most docker_service dependencies
  - { role: "nickjj.docker", tags: ["docker"] }

So I guess compose installed.

I could run the docker-compose binary before I did the pip install. The docker-compose binary is pulled from the web here: https://github.com/nickjj/ansible-docker/blob/master/tasks/main.yml#L129

But nothing is pulling docker-compose from pip: https://github.com/nickjj/ansible-docker/blob/master/tasks/main.yml#L22

I think docker_service relies on it to be installed via pip.

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024 1

This has been fully addressed in v1.6.0. Check the README file for details.

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024

When you run it directly on your host, are you using a virtualenv?

from ansible-docker.

obilodeau avatar obilodeau commented on July 20, 2024

I run ansible-playbook directly on my machine (arch linux, python3 by default) but the error is when I run a playbook on a server in my inventory (ubuntu 18.04).

Re-reading myself, I said:

Running pip install docker-compose on the host fixed the issue.

I meant guest or server not host. Edited description to fix it.

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024

Did you configure this role not to install compose, or did you end up having both installed after you pip installed docker-compose?

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024

It does require it if you use the compose bits but not everyone using this role uses docker_service.

Right now pip install docker is happening mainly because docker_login requires it.

I'm torn on forcing users to install compose through pip because it's not as simple as just pip installing it, since it may or may not involve virtual envs.

from ansible-docker.

obilodeau avatar obilodeau commented on July 20, 2024

Maybe that's a reasonable compromise. One where this role would allow you to configure which pip packages to install, this way if you need compose, you add it, but it defaults to just docker.

I'll check if I can figure out how to do this and submit a PR.

I don't manage any containers with Ansible because I don't use Ansible to initiate deploying my web applications. I only use Ansible to get my machines to the point where everything can be ran, but then I use either git hooks or CI services to handle deploying the app, and this is where I set up things like stopping compose, rebuilding, pulling, etc. and bringing it all back up.

Cool. Thanks for the input.

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024

You're more than welcome to open a PR on this, but if you do it, please follow the standards on how the rest of this role is laid out in terms of variable naming, ordering, and how it appears in the README.

Although figuring out how to deal with virtual envs is up in the air still. Either by supplying an optional executable property on the pip module, or using the virtualenv / virtualenv_command -- both would be config options of this role. I think one of them will be necessary and I don't know the answer to this yet because I use neither in production, so we would have to research it.

from ansible-docker.

shoe-diamente avatar shoe-diamente commented on July 20, 2024

I'm having this problem.
My playbook is this:

  tasks:
    - name: Update and upgrade apt packages
      apt:
        upgrade: 'yes'
        update_cache: yes
        cache_valid_time: 3600
        # Reference: https://github.com/ansible/ansible/issues/56832
        force_apt_get: yes 

    - name: Install Docker & Docker compose
      include_role:
        name: "nickjj.docker"
        apply:
          tags: 
            - docker

    - name: Install python packages for ansible
      apt:
        package:
        - python-apt
        - python-docker
        force_apt_get: yes 

    - name: Start services
      become: yes
      docker_compose:
        project_src: "{{ base_path }}"
        state: present

and I'm getting:

TASK [Start services] **********************************************************
fatal: [vagrant]: FAILED! => {"changed": false, "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: Traceback (most recent call last):\n  File \"/tmp/ansible_docker_compose_payload_W_NWRI/ansible_docker_compose_payload.zip/ansible/modules/cloud/docker/docker_compose.py\", line 477, in <module>\nImportError: No module named compose\n"}

Doesn't this role install docker as well as docker-compose?

from ansible-docker.

shoe-diamente avatar shoe-diamente commented on July 20, 2024

If I add:

     vars:
        ansible_python_interpreter: "{{ '/usr/bin/env python-docker' }}"

to the task like so:

    - name: Start services
      become: yes
      docker_compose:
        project_src: "{{ base_path }}"
        state: present
      vars:
        ansible_python_interpreter: "{{ '/usr/bin/env python-docker' }}"

I get:

TASK [Start services] ***********************************************************
fatal: [vagrant]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on ubuntu1804.localdomain's Python /usr/local/bin/python-docker. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via pip install docker or pip install docker-py (Python 2.6). The error was: No module named 'docker'"}

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024

@shoe-diamente

This role installs Docker and Docker Compose but it's not going to start your Docker Compose projects. Managing your applications after Docker and Docker Compose is installed is up to you since that's very much project specific.

You also don't need to apt install python-apt and python-docker.

The docs do mention under "Working with Ansible's docker_* modules":

At either the inventory, playbook or task level you'll need to set
ansible_python_interpreter: "/usr/bin/env python-docker".
This works because this role symlinks the Virtualenv's Python binary to python-docker.

This is currently working when I use the docker_login module to optionally login to a registry in the role. By default this role pip installs docker and docker compose so that "docker" module should be available.

from ansible-docker.

shoe-diamente avatar shoe-diamente commented on July 20, 2024

I've destroyed the VM. Removed the tasks that installed python-apt and python-docker and added:

      vars:
        ansible_python_interpreter: "{{ '/usr/bin/env python-docker' }}"

now it stops even before at a docker_image task:

    - name: Load services
      become: yes
      docker_image:
        load_path: "{{ base_path }}/{{ item }}.tar"
        name: {{ item }}
        tag: latest
        source: load
      with_items:
        - database
        - server
        - client
      vars:
        ansible_python_interpreter: "{{ '/usr/bin/env python-docker' }}"

with:

failed: [vagrant] (item=database) => {"ansible_loop_var": "item", "changed": false, "item": "database", "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on ubuntu1804.localdomain's Python /usr/local/bin/python-docker. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` or `pip install docker-py` (Python 2.6). The error was: No module named 'docker'"}

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024

Did this role's pip tasks run to install those packages?

Did you try SSHing into the server and seeing if you can run /usr/bin/env python-docker?

from ansible-docker.

shoe-diamente avatar shoe-diamente commented on July 20, 2024

Did this role's pip tasks run to install those packages?

Currently the only packages installed are the ones from ansible-docker's role. I've also attempted to run this task:

    - name: Pip install docker for Ansible's docker_* modules
      pip:
        name: 
          - docker
          - "docker-compose"

after ansible-docker's role and before the failing task to no success (same error).

Did you try SSHing into the server and seeing if you can run /usr/bin/env python-docker?

It seems like it can run that:

$ /usr/bin/env python-docker
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from ansible-docker.

nickjj avatar nickjj commented on July 20, 2024

Within that python prompt can you run import docker and import docker_compose without getting an error?

Also you should be running your custom Docker Compose task as the Docker user.

Also, I think the issue you're describing is unrelated to this one, so please open up a new issue with a minimal reproducible set up where this doesn't work, because when I run the role against Ubuntu 18.04 here, everything is working and no one has else has mentioned having issues with this bit of functionality.

from ansible-docker.

shoe-diamente avatar shoe-diamente commented on July 20, 2024

Opened #74

from ansible-docker.

parasharsingh8086 avatar parasharsingh8086 commented on July 20, 2024

I have RHEL7 system where i'm trying to install AWX. Getting error msg:

TASK [local_docker : Start the containers] *****************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unable to load docker-compose. Try pip install docker-compose. Error: No module named compose"}
to retry, use: --limit @/i01/awx/installer/install.retry

[root@installer]# docker --version
Docker version 1.13.1, build 7f2769b/1.13.1
[root@installer]# docker-compose -version
docker-compose version 1.25.1, build a82fef07
[root@installer]#

I think pip command doesn't work in Red Hat Linux.

Can someone advise how to resolve this issue to proceed with AWX install?

from ansible-docker.

shoe-diamente avatar shoe-diamente commented on July 20, 2024

@parasharsingh8086 Have you tried the latest version? #74 (comment)

from ansible-docker.

librra avatar librra commented on July 20, 2024

@nickjj You save me :)

from ansible-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.