
Kolla Ansible's bootstrap-servers command provides support for installing the Docker engine. This is currently done using the packages at https://apt.dockerproject.org and https://yum.dockerproject.org. These packages are outdated, with the most recent packages from May 2017 - docker-engine-17.05. The source for up to date docker packages is https://download.docker.com, which was introduced with the move to Docker Community Edition (CE) and Docker Enterprise Edition (EE). This change adds support to bootstrap-servers for Docker CE for CentOS and Ubuntu. It also adds a new variable, 'enable_docker_repo', which controls whether a package repository for Docker will be enabled. It also adds a new variable, 'docker_legacy_packages', which controls whether the legacy packages at dockerproject.org will be used or the newer packages at docker.com. The default value for this variable is 'false', meaning to use Docker CE. Upgrading from docker-engine to docker-ce has been tested on CentOS 7.5 and Ubuntu 16.04, by running 'kolla-ansible bootstrap-servers' with 'docker_legacy_packages' set to 'false'. The upgrades were successful, but result in all containers being stopped. For this reason, the bootstrap-servers command checks running containers prior to upgrading packages, and ensures they are running after the package upgrade is complete. As mentioned in the release note, care should be taken when upgrading Docker with clustered services, which could lose quorum. To avoid this, use --serial or --limit to apply the change in batches. Change-Id: I6dfd375c868870f8646ef1a8f02c70812e8f6271 Implements: blueprint docker-ce
152 lines
3.7 KiB
YAML
152 lines
3.7 KiB
YAML
---
|
|
- name: Update apt cache
|
|
apt:
|
|
update_cache: yes
|
|
become: True
|
|
when: ansible_os_family == 'Debian'
|
|
|
|
- name: Update yum cache
|
|
yum:
|
|
update_cache: yes
|
|
become: True
|
|
when: ansible_os_family == 'RedHat'
|
|
|
|
# TODO(inc0): Gates don't seem to have ufw executable, check for it instead of ignore errors
|
|
- name: Set firewall default policy
|
|
become: True
|
|
ufw:
|
|
state: disabled
|
|
policy: allow
|
|
when: ansible_os_family == 'Debian'
|
|
ignore_errors: yes
|
|
|
|
- name: Check if firewalld is installed
|
|
command: rpm -q firewalld
|
|
register: firewalld_check
|
|
failed_when: firewalld_check.rc > 1
|
|
when: ansible_os_family == 'RedHat'
|
|
|
|
- name: Disable firewalld
|
|
become: True
|
|
service:
|
|
name: "{{ item }}"
|
|
enabled: false
|
|
state: stopped
|
|
with_items:
|
|
- firewalld
|
|
when:
|
|
- ansible_os_family == 'RedHat'
|
|
- firewalld_check.rc == 0
|
|
|
|
# Upgrading docker engine may cause containers to stop. Take a snapshot of the
|
|
# running containers prior to a potential upgrade of Docker.
|
|
|
|
- name: Check which containers are running
|
|
command: docker ps -f 'status=running' -q
|
|
become: true
|
|
# If Docker is not installed this command may exit non-zero.
|
|
failed_when: false
|
|
changed_when: false
|
|
register: running_containers
|
|
|
|
- name: Install apt packages
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
become: True
|
|
with_items: "{{ debian_pkg_install }}"
|
|
when: ansible_os_family == 'Debian'
|
|
register: apt_install_result
|
|
|
|
- name: Install deltarpm packages
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
become: True
|
|
with_items:
|
|
- deltarpm
|
|
when: ansible_os_family == 'RedHat'
|
|
|
|
- name: Install yum packages
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
become: True
|
|
with_items: "{{ redhat_pkg_install }}"
|
|
when: ansible_os_family == 'RedHat'
|
|
register: yum_install_result
|
|
|
|
# If any packages were updated, and any containers were running, wait for the
|
|
# daemon to come up and start all previously running containers.
|
|
|
|
- block:
|
|
- name: Wait for Docker to start
|
|
command: docker info
|
|
become: true
|
|
changed_when: false
|
|
register: result
|
|
until: result is success
|
|
retries: 6
|
|
delay: 10
|
|
|
|
- name: Ensure containers are running after Docker upgrade
|
|
command: "docker start {{ running_containers.stdout }}"
|
|
become: true
|
|
when:
|
|
- install_result is changed
|
|
- running_containers.rc == 0
|
|
- running_containers.stdout != ''
|
|
vars:
|
|
install_result: "{{ yum_install_result if ansible_os_family == 'RedHat' else apt_install_result }}"
|
|
|
|
- name: Install virtualenv packages
|
|
package:
|
|
name: python-virtualenv
|
|
state: present
|
|
become: True
|
|
when: virtualenv is not none
|
|
|
|
- name: Install pip
|
|
easy_install:
|
|
name: pip
|
|
virtualenv: "{{ virtualenv is none | ternary(omit, virtualenv) }}"
|
|
virtualenv_site_packages: "{{ virtualenv is none | ternary(omit, virtualenv_site_packages) }}"
|
|
become: True
|
|
|
|
- name: Install latest pip in the virtualenv
|
|
pip:
|
|
name: pip
|
|
state: latest
|
|
virtualenv: "{{ virtualenv }}"
|
|
virtualenv_site_packages: "{{ virtualenv_site_packages }}"
|
|
become: True
|
|
when: virtualenv is not none
|
|
|
|
- name: Install docker SDK for python
|
|
pip:
|
|
name: docker
|
|
state: latest
|
|
virtualenv: "{{ virtualenv is none | ternary(omit, virtualenv) }}"
|
|
virtualenv_site_packages: "{{ virtualenv is none | ternary(omit, virtualenv_site_packages) }}"
|
|
become: True
|
|
|
|
- name: Remove packages
|
|
package:
|
|
name: "{{ item }}"
|
|
state: absent
|
|
with_items: "{{ ubuntu_pkg_removals }}"
|
|
become: True
|
|
when:
|
|
- ansible_distribution|lower == "ubuntu"
|
|
- item != ""
|
|
|
|
- name: Remove packages
|
|
package:
|
|
name: "{{ item }}"
|
|
state: absent
|
|
with_items: "{{ redhat_pkg_removals }}"
|
|
become: True
|
|
when:
|
|
- ansible_os_family == 'RedHat'
|
|
- item != ""
|