Przeglądaj źródła

Downgrade to docker 1.8.2 if installing OSE < 3.2

Scott Dodson 9 lat temu
rodzic
commit
18b52f2c4e

+ 2 - 0
roles/docker/defaults/main.yml

@@ -0,0 +1,2 @@
+---
+docker_version: ''

+ 19 - 22
roles/docker/tasks/main.yml

@@ -1,32 +1,29 @@
 ---
 # tasks file for docker
 
-# Avoid docker 1.9 when installing origin < 1.2 or OSE < 3.2 on RHEL/Centos and
-# See: https://bugzilla.redhat.com/show_bug.cgi?id=1304038
+- name: Get current installed version if docker_version is specified
+  command: "{{ repoquery_cmd }} --installed --qf '%{version}' docker"
+  when:  not openshift.common.is_atomic | bool and docker_version != ''
+  register: docker_version_result
+  changed_when: false
 
-- name: Default to latest docker for 1.2/3.2 or Fedora
-  set_fact:
-    docker_version: ''
-  when: openshift.common.version_gte_3_2_or_1_2 | bool or ansible_distribution == 'Fedora'
+- name: Downgrade docker if necessary
+  command: "{{ ansible_pkg_mgr }} downgrade -y docker-{{ docker_version }}"
+  register: docker_downgrade_result
+  when: not docker_version_result | skipped and docker_version_result | default('0.0', True) | version_compare(docker_version, 'gt')
 
-- name: Gather latest version of docker
-  shell: >
-    yum list available -e 0 -q "docker" 2>&1 | tail -n +2 | awk '{ print $2 }' | sort -r | tr '\n' ' ' | tail -n 1
-  register: latest_docker
-  when: not openshift.common.version_gte_3_2_or_1_2 | bool and ansible_distribution != 'Fedora'
-
-- name: Check if Docker 1.9 is the latest
-  set_fact:
-    docker19_is_latest: "{{ True if '1.9' in latest_docker.stdout else False }}"
-  when: not openshift.common.version_gte_3_2_or_1_2 | bool and ansible_distribution != 'Fedora'
+- name: Install docker
+  action: "{{ ansible_pkg_mgr }} name=docker{{ '-' + docker_version if docker_version != '' else '' }} state=present"
+  when: not openshift.common.is_atomic | bool and not docker_downgrade_result | changed
 
-- set_fact:
-    docker_version: "{{ '-1.8.2' if docker19_is_latest | bool else ''}}"
-  when: not openshift.common.version_gte_3_2_or_1_2 | bool and ansible_distribution != 'Fedora'
+- stat: path=/etc/sysconfig/docker
+  register: docker_check
+  when: docker_downgrade_result | changed
 
-- name: Install docker
-  action: "{{ ansible_pkg_mgr }} name=docker{{ docker_version }} state=present"
-  when: not openshift.common.is_atomic | bool
+- name: Remove deferred deletion for downgrades from 1.9
+  command: >
+    sed -i 's/--storage-opt dm.use_deferred_deletion=true//' /etc/sysconfig/docker-storage
+  when: docker_downgrade_result | changed and docker_check.stat.exists | bool and docker_version_result | default('0.0', True) | version_compare('1.9', '>=') and docker_version | version_compare('1.9', '<')
 
 - name: enable and start the docker service
   service:

+ 1 - 1
roles/docker/vars/main.yml

@@ -1,3 +1,3 @@
 ---
-
+repoquery_cmd: "{{ 'dnf repoquery --latest-limit 1 -d 0' if ansible_pkg_mgr == 'dnf' else 'repoquery' }}"
 udevw_udevd_dir: /etc/systemd/system/systemd-udevd.service.d

+ 0 - 1
roles/openshift_cli/meta/main.yml

@@ -13,6 +13,5 @@ galaxy_info:
   - cloud
 dependencies:
 - role: openshift_docker
-  when: openshift.common.is_containerized | bool
 - role: openshift_common
 - role: openshift_cli_facts

+ 1 - 0
roles/openshift_docker/meta/main.yml

@@ -12,5 +12,6 @@ galaxy_info:
   categories:
   - cloud
 dependencies:
+- role: openshift_repos
 - role: openshift_docker_facts
 - role: docker

+ 16 - 0
roles/openshift_docker_facts/tasks/main.yml

@@ -37,3 +37,19 @@
 - set_fact:
     docker_options: "{{ openshift.docker.options | default(omit) }}"
   when: not openshift.docker.hosted_registry_insecure | default(False) | bool
+
+# Avoid docker 1.9 when installing origin < 1.2 or OSE < 3.2 on RHEL/Centos and
+# See: https://bugzilla.redhat.com/show_bug.cgi?id=1304038
+- name: Gather common package version
+  command: >
+    {{ repoquery_cmd }} --qf '%{version}' "{{ openshift.common.service_type}}"
+  register: common_version
+  failed_when: false
+  changed_when: false
+  when: not openshift.common.is_atomic | bool
+
+- name: Set docker version to be installed
+  set_fact:
+    docker_version: "{{ '1.8.2' }}"
+  when: " ( common_version.stdout | default('0.0', True) | version_compare('3.2','<') and openshift.common.service_type == 'atomic-openshift' ) or
+          ( common_version.stdout | default('0.0', True) | version_compare('1.2','<') and openshift.common.service_type == 'origin' )"

+ 2 - 0
roles/openshift_docker_facts/vars/main.yml

@@ -0,0 +1,2 @@
+---
+repoquery_cmd: "{{ 'dnf repoquery --latest-limit 1 -d 0' if ansible_pkg_mgr == 'dnf' else 'repoquery' }}"

+ 1 - 1
roles/openshift_facts/tasks/main.yml

@@ -15,7 +15,7 @@
 - set_fact:
     l_is_atomic: "{{ ostree_output.rc == 0 }}"
 - set_fact:
-    l_is_containerized: "{{ l_is_atomic or containerized | default(false) | bool }}"
+    l_is_containerized: "{{ (l_is_atomic | bool) or (containerized | default(false) | bool) }}"
 
 - name: Ensure PyYaml is installed
   action: "{{ ansible_pkg_mgr }} name=PyYAML state=present"

+ 1 - 0
roles/openshift_master/meta/main.yml

@@ -12,6 +12,7 @@ galaxy_info:
   categories:
   - cloud
 dependencies:
+- role: openshift_docker
 - role: openshift_cli
 - role: openshift_cloud_provider
 - role: openshift_master_facts