Skip to content

Commit

Permalink
Handle docker python packages to support Ansible2.3+ (#151)
Browse files Browse the repository at this point in the history
* Add an editorconfig file

* Revert "disable install of docker-py on 16.04+"

The issue is related to docker-compose/docker-py/docker packages messup not
to the Ubuntu version.
See: ansible/ansible#20492
The #136 PR partially fixed
it.

* Revert "Change ansible version check"

Ansible 2.3 will handle both docker and docker-py python packages.
See: ansible/ansible@e2a1ce2
and ansible/ansible#20492 (comment)

* Add a gitignore file

* Handle Docker Python packages for Ansible 2.3+

* Clean Docker Python packages

When updating to Ansible 2.3+ docker-py might no longer be needed.

* Add container tasks into the Vagrant playbook

To ensure docker modules actually work after the role installation.
  • Loading branch information
Jonathan Piron authored and angstwad committed Mar 28, 2017
1 parent 5877697 commit c4b3d26
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

# default configuration
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vagrant/
*.log
env/
venv/
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ docker_https_proxy:
# Flags for whether to install pip packages
pip_install_pip: true
pip_install_setuptools: true
pip_install_docker_py: true
# pip_install_docker is ignored if pip_install_docker_compose is true as docker-compose as a dependency over docker.
# See var/main.yml for more information.
pip_install_docker: true
pip_install_docker_compose: true
install_docker_py_on_1604: false
# Versions for the python packages that are installed
pip_version_pip: latest
pip_version_setuptools: latest
pip_version_docker_py: latest
# pip_version_docker is ignored if pip_install_docker_compose is true as docker-compose as a dependency over docker.
# See var/main.yml for more information.
pip_version_docker: latest
pip_version_docker_compose: latest
# If this variable is set to true kernel updates and host restarts are permitted.
Expand Down
9 changes: 6 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ docker_https_proxy:
# Flags for whether to install pip packages
pip_install_pip: true
pip_install_setuptools: true
pip_install_docker_py: true
# pip_install_docker is ignored if pip_install_docker_compose is true as docker-compose as a dependency over docker.
# See var/main.yml for more information.
pip_install_docker: true
pip_install_docker_compose: true
install_docker_py_on_1604: false

# Versions for the python packages that are installed
pip_version_pip: latest
pip_version_setuptools: latest
pip_version_docker_py: latest
# pip_version_docker is ignored if pip_install_docker_compose is true as docker-compose as a dependency over docker.
# See var/main.yml for more information.
pip_version_docker: latest
pip_version_docker_compose: latest

# If this variable is set to true kernel updates and host restarts are permitted.
Expand Down
20 changes: 17 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@
module in Ansible < 2.3
when: pip_install_docker_compose and _pip_version_docker_compose != pip_version_docker_compose

# See vars/main.yml for more information on this.
- name: Clean previous docker-py package if installing docker.
pip:
name: docker-py
state: absent
when: (_pip_install_docker or pip_install_docker_compose) and _pip_docker_package_name == 'docker'

# See vars/main.yml for more information on this.
- name: Clean previous docker package if installing docker-py.
pip:
name: docker
state: absent
when: (_pip_install_docker or pip_install_docker_compose) and _pip_docker_package_name == 'docker-py'

# Upgrade pip with pip to fix angstwad/docker.ubuntu/pull/35 and docker-py/issues/525
- name: Install pip, setuptools, docker-py and docker-compose with pip
pip:
Expand All @@ -178,9 +192,9 @@
- name: setuptools
version: "{{ pip_version_setuptools }}"
install: "{{ pip_install_setuptools }}"
- name: docker-py
version: "{{ pip_version_docker_py }}"
install: "{{ pip_install_docker_py and (install_docker_py_on_1604 or not ansible_distribution_version|version_compare('16.04', '>=')) }}"
- name: "{{ _pip_docker_package_name }}"
version: "{{ pip_version_docker }}"
install: "{{ _pip_install_docker }}"
- name: docker-compose
version: "{{ _pip_version_docker_compose }}"
install: "{{ pip_install_docker_compose }}"
Expand Down
16 changes: 16 additions & 0 deletions tests/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@
roles:
- role: docker.ubuntu
kernel_update_and_reboot_permitted: yes

tasks:
- name: Create a dummy container
docker_container:
name: foobar
pull: true
image: busybox
state: started
when: _pip_install_docker or pip_install_docker_compose
register: container_creation

- name: Remove the dummy container
docker_container:
name: foobar
state: absent
when: container_creation.changed
33 changes: 29 additions & 4 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
---
# Downgrade docker-compose version if ansible version < 2.3 and docker-compose > 1.9.0
# Because of docker-compose 1.10+ requires docker python package (instead of the docker-py one)
# which is incompatible with the docker_container module in Ansible < 2.3
# To use Docker Ansible modules, managed nodes require some Docker Python packages :
# * `docker-py` (renamed into `docker` since the 2.0.0 version);
# * `docker-compose` which is required by the docker_service Ansible module.
#
# The `docker` python package introduces some backward incompatible changes is version 2.0.0.
# Ansible 2.3+ is required to run this new version. Previous Ansible versions have to use docker-py<=1.10.6.
# The `docker-compose` python package has a dependency over the docker/docker-py package.
# The `docker-compose` 1.9.0 is the latest version to be compatible with the docker<2.0.0.
#
# To sum up:
# * with Ansible < 2.3:
# * you have to use docker-py<=1.10.6 due to backward incompatibilities of next versions
# * you have to use docker-compose<=1.9.0 due to docker-compose>1.9.0 using newer versions of docker-py.

# Compute the `docker` Python package's version to use.
_pip_version_docker: >-
{{ '1.10.6' if ansible_version.full | version_compare('2.3', '<')
and (pip_version_docker=='latest' or pip_version_docker | version_compare('1.10.6', '>'))
else pip_version_docker }}
# Compute the `docker` Python package's name according to its version.
_pip_docker_package_name: "{{ 'docker-py' if pip_version_docker | version_compare('1.10.6', '<=') else 'docker' }}"

# Determine whether to install the `docker` package or not. The `docker-compose` Python package has a dependency over the `docker` Python package.
# So when installing the `docker-compose` package we'd rather let it handle the `docker` package version to prevent version mismatches.
_pip_install_docker: "{{ not pip_install_docker_compose and pip_install_docker }}"

# Compute the `docker-compose` Python package's version to use.
_pip_version_docker_compose: >-
{{ '1.9.0' if ansible_version.full | version_compare('2.3', '<=')
{{ '1.9.0' if ansible_version.full | version_compare('2.3', '<')
and (pip_version_docker_compose=='latest' or pip_version_docker_compose | version_compare('1.9.0', '>'))
else pip_version_docker_compose }}

0 comments on commit c4b3d26

Please sign in to comment.