diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3fee862 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +# default configuration +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..817dda8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vagrant/ +*.log +env/ +venv/ diff --git a/README.md b/README.md index a0d1a42..3633051 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/defaults/main.yml b/defaults/main.yml index d1a7563..51302e3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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. diff --git a/tasks/main.yml b/tasks/main.yml index e6b0df6..b21babe 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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: @@ -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 }}" diff --git a/tests/vagrant.yml b/tests/vagrant.yml index 6054a9b..3b3cc73 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -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 diff --git a/vars/main.yml b/vars/main.yml index 39e95d1..5fe385e 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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 }}