ansible-docker: docker_service: Unable to load docker-compose.

Error:

Unable to load docker-compose. Try `pip install docker-compose`. Error: No module named compose

playbook:

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

  tasks:
  - name: test docker-compose
    docker_service:
      project_src: test

Stack trace:

The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_docker_service_payload_U2NKy6/__main__.py", line 456, in <module>
    from compose import __version__ as compose_version

fatal: [138.xx.xx.183]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "build": false,
            "cacert_path": null,
            "cert_path": null,
            "debug": false,
            "definition": null,
            "dependencies": true,
            "docker_host": "unix://var/run/docker.sock",
            "files": null,
            "hostname_check": false,
            "key_path": null,
            "nocache": false,
            "project_name": null,
            "project_src": "../<...>",
            "pull": false,
            "recreate": "smart",
            "remove_images": null,
            "remove_orphans": false,
            "remove_volumes": false,
            "restarted": false,
            "scale": null,
            "services": null,
            "ssl_version": null,
            "state": "present",
            "stopped": false,
            "timeout": 10,
            "tls": false,
            "tls_hostname": "localhost",
            "tls_verify": false
        }
    },
    "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: No module named compose"
}

Workaround:

Running pip install docker-compose on the server managed by ansible fixed the issue.

Version infos

galaxy info:

Role: nickjj.docker
	description: Install Docker and optionally Docker Compose.
	active: True
	commit: d498cc15f393312ae9e104e13cc3ac7d07365c8d
	commit_message: Update README to link to the latest release
	commit_url: https://api.github.com/repos/nickjj/ansible-docker/git/commits/d498cc15f393312ae9e104e13cc3ac7d07365c8d
	company: 
	created: 2016-10-08T23:13:50.040014Z
	dependencies: []
	download_count: 2838
	forks_count: 69
	galaxy_info:
		author: Nick Janetakis
		galaxy_tags: ['containers', 'compose', 'docker', 'packaging', 'system']
		license: MIT
		min_ansible_version: 2.5
		platforms: [{'name': 'Ubuntu', 'versions': ['xenial', 'bionic']}, {'name': 'Debian', 'versions': ['jessie', 'stretch']}]
		role_name: docker
	github_branch: master
	github_repo: ansible-docker
	github_user: nickjj
	id: 12606
	imported: 2018-11-08T21:18:19.792556-05:00
	install_date: Thu Nov 15 16:08:42 2018
	intalled_version: v1.5.0
	is_valid: True
	issue_tracker_url: https://github.com/nickjj/ansible-docker/issues
	license: MIT
	min_ansible_version: 2.5
	modified: 2018-11-09T02:18:19.792718Z
	open_issues_count: 0
	path: ['/home/xxx/.ansible/roles', '/usr/share/ansible/roles', '/etc/ansible/roles']
	role_type: ANS
	stargazers_count: 195
	travis_status_url: 

ansible version:

ansible --version
ansible 2.7.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/olivier/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.1 (default, Oct 22 2018, 10:41:28) [GCC 8.2.1 20180831]

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (9 by maintainers)

Most upvoted comments

I used the command bellow:

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

This solved my problem. Tks.

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.

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?

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

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.