Feb 9, 2017, 13:07

Ansible, docker_service module issue and dependency hell

I struggled with deploying web services via Ansible to staging CoreOS host and that's something that looks like a hell!

I received one error, then another with just simple-simple steps like

- name: IT-Premium docker-compose deploy
  hosts: coreos
  tasks:
    - name: Install docker-py
      pip: name=docker-py executable=/home/core/bin/pip

    - name: Install PyYAML
      pip: name=PyYAML executable=/home/core/bin/pip

    - name: Install docker-compose
      pip: name=docker-compose executable=/home/core/bin/pip version=1.9.0

    - name: Creates it-premium directory
      file: path=/home/core/it-premium state=directory

    - name: copy docker-compose.yml
      copy: src=./docker-compose.yml dest=/home/core/it-premium/docker-compose.yml
      tags: deploy

    - name: copy sqlite
      copy: src=./sqlite dest=/home/core/it-premium/ mode=0644
      tags: deploy

    - name: docker registry login
      docker_login:
        registry: "registry.it-expert.com.ua"
        username: nexus
        password: "{{gitlab_password}}"

    - name: pull images
      docker_image:
        name: registry.it-expert.com.ua/nexus/it-premium
        state: present

    - name: launch it-premium docker-compose with 2 containers
      tags: step1
      docker_service:
        project_src: it-premium
        state: present
        build: no
      register: output

    - debug:
        var: output

You can notice version of docker-compose 1.9.0, which is supplied there. That's because of issue with
Error: cannot import name 'IPAMConfig'
thrown by docker_service.

And here is why https://github.com/ansible/ansible/issues/20492

This is due to your docker-compose version.
The docker-py package has been renamed into docker in version 2.0 (https://github.com/docker/docker-py/releases/tag/2.0.0). And in this version, Docker.Client has been renamed into docker.APIClient.
Docker-compose 1.10+ now requires docker instead of docker-py. And due to his name the docker package is before the docker-py one in the PYTHONPATH leading to the import error.
A workaround is to downgrade your docker-compose version to 1.9.0 the time the Ansible docker_container module updates its dependencies from docker-py to docker.

That's something like «piss on you, dirty user, because we do not care about backward compatibility».

Because when you change something, it is like delete old state and introduce new one instead. And when you delete something, that could broke anything that relies on state.

How to do instead? Just ADD something new without removal. Call it with new namespace, new function name and just use!

Share