Skip to content

Commit

Permalink
more kernel update changes, improve testing mostly, also removed kern…
Browse files Browse the repository at this point in the history
…el update components from the role. (#11)

* improve testing & remove additional kernel update components from the role

+ Remove kernel update plays from this role moved to ansible-role_kernel-update

+ a bunch of configuration changes and modifications to how we run the tests.
      + use vagrant generated inventory
      + provisioning done with ansible
      + parallel execution of tests on 14.04 & 12.04
      + ansible.cfg uses become instead of sudo
  • Loading branch information
yarloocll authored Jan 25, 2017
1 parent a85e163 commit 2a3155f
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 147 deletions.
65 changes: 47 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,63 @@ Docker versions.
Upgrade Support
---------------

Some Docker Engine upgrade paths have known issues. There's code in this role that attempts to
resolve those issues, with minimum disruption, if those upgrade paths are encountered. The
intention is to not require containers to be recreated.
This role no longer directly supports upgrading docker from a previous version. Any additional
steps required as a part of an upgrade should be taken care of in a separate role or playbook.

This code isn't intended to catch everything; an attempt has been made to make it reasonable and
non-harmful, but it hasn't been tested for all possible upgrade paths, nor with features like
non-local storage drivers. With that in mind, this behavior is optional and is disabled by default.

The issues we attempt to resolve are documented in the "repair_docker_data_volumes" module.
Kernel Requirements
-------------------

Docker has some kernel requirements for proper usage with Ubuntu. We have a new role
ansible-role_kernel_update which will assist with the kernel requirements.

Role Variables
--------------

- `docker_version` : this variable controls the version of Docker that is installed. Required.
- `docker_version`: this variable controls the version of Docker that is installed. Required.
If version `1.5.0` is selected, LXC Docker will be used; otherwise the stated version of
Docker Engine will be installed (if available).
- `docker_daemon_flags` : Empty by default. This variable holds flags that will be passed to
- `docker_daemon_flags`: Empty by default. This variable holds flags that will be passed to
the Docker daemon on startup. (This is implemented by modifying the file `/etc/default/docker`.)
- `cgroup_lite_pkg_state` : When installing on an Ubuntu 13.10 host, the role will install the
`cgroup-lite` package to provide the required cgroups support. This variable can be set to
`latest` - the default - or to `present`. In the former case, the package will be updated, if
necessary, when the role is run. In the latter, the package will only be added if it is not
present.
- `kernel_pkg_state` : For 13.04+, this role will install a `linux-image-extra-<version>`
package. This parameter works the same way as `cgroup_lite_package_state`, except controlling
this package.
- `docker_daemon_startup_retries`: this variable controls how many times we poll docker to
confirm it is running after we start or restart it before giving up. Defaults to 10.

Documentation
-------------

The documentation for working with Docker on Ubuntu is available online but there has been
some refactoring of the documentation since the original writing.

* https://docs.docker.com/engine/installation/linux/ubuntu/
* (old) https://github.com/docker/docker.github.io/blob/master/engine/installation/linux/ubuntulinux.md
* (new) https://github.com/docker/docker.github.io/blob/master/engine/installation/linux/ubuntu.md

The *old* documentation is what was previously available online and the *new* documentation is what is
currently available online. As of this writing the documentation is at commit '45a19ec' & '9093e0a' respectively.

* (old) https://github.com/docker/docker.github.io/blob/45a19ec/engine/installation/linux/ubuntulinux.md
* (new) https://github.com/docker/docker.github.io/blob/9093e0a/engine/installation/linux/ubuntu.md

Links to documentation will therefore get pinned to a particular commit to maintain access
to historical information which may get removed (or moved) in later versions. Maintainers
should check the master branch when updating the role and update links when possible.

Currently the new documentations says docker is only supported on 14.04[LTS], 16.04[LTS], & 16.10
but the old documentation has some instructions for 12.04[LTS].

12.04 may not have support due to issues with older kernels. Docker documentation mentions some
prerequisites when installing from a binary that could be informative and there is a known
issue with docker running on linux kernels less than 3.19 that could imply 12.04 isn't supported.

* https://docs.docker.com/engine/installation/binaries/#/prerequisites
* https://github.com/docker/docker/issues/21704#issuecomment-235365424

Additional Resources
--------------------

Users of this role might also consider reviewing our other ansible roles.
In particular:

* https://github.com/locationlabs/ansible-role_docker-base

Testing
-------
Expand Down
10 changes: 2 additions & 8 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
---

kernel_pkg_state: latest
cgroup_lite_pkg_state: latest
ssh_port: 22

docker_role_apt_cache_valid_time: 7200

# These flags are passed to the Docker daemon on startup.
docker_daemon_flags: ""


# When we start / restart Docker, this role waits until it is ready before
# proceeding. This variable controls how long we wait before giving up.
# proceeding. This variable controls how many times we retry the service before giving up.
# This value should be OK for all but the slowest servers.
docker_daemon_startup_timeout_sec: 10
docker_daemon_startup_retries: 10
16 changes: 5 additions & 11 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
---
galaxy_info:
author: Paul Durivage
description: Docker on Ubuntu greater than 12.04
author: Location Labs
description: Docker on Ubuntu >= 12.04
license: Apache v2.0
min_ansible_version: 1.2
min_ansible_version: 1.9.6
platforms:
- name: Ubuntu
versions:
- precise
- raring
- saucy
- trusty
categories:
- development
- packaging
- system
- precise # 12.04
- trusty # 14.04
dependencies: []
# List your role dependencies here, one per line. Only
# dependencies available via galaxy should be listed here.
Expand Down
1 change: 1 addition & 0 deletions tasks/docker-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
name: "docker-engine={{ docker_version }}-*~{{ ansible_distribution_release }}"
state: present
register: r_docker_package_install
when: not check_mode
5 changes: 4 additions & 1 deletion tasks/lxc-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
update_cache: yes

- name: Install LXC Docker
apt: pkg="lxc-docker-{{ docker_version }}" state=present
apt:
name: "lxc-docker-{{ docker_version }}"
state: present
register: r_docker_package_install
when: not check_mode
77 changes: 26 additions & 51 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---
# tasks file for docker.ubuntu
# Main tasks file

# noop to detect check mode for older versions of ansible.
# http://docs.ansible.com/ansible/playbooks_checkmode.html#information-about-check-mode-in-variables
- command: /bin/true
register: noop_result

- set_fact: check_mode={{ noop_result|skipped }}

# These are the version of Ubuntu for which this role has been tested.
- name: Fail if not a new release of Ubuntu
Expand All @@ -10,54 +17,20 @@
fail: msg="Required variable \"docker_version\" is not defined."
when: docker_version is not defined

# https://docs.docker.com/engine/installation/linux/ubuntulinux/#/prerequisites-by-ubuntu-version
# - 12.04: Docker requires the 3.13 kernel version.
# Ensure the trusty kernel is installed.
# - 14.04: Support aufs via the linux-image-extra-* kernel package.
# Achieve this with the xenial kernel, which depends on the
# corresponding extra package, to address issues with kernels
# before 3.19 at the same time.
# https://github.com/docker/docker/issues/21704#issuecomment-235365424
- name: Install HWE kernel on pre-16.04 LTS
apt:
pkg: "{{ item.name }}"
state: latest
update_cache: yes
cache_valid_time: "{{ docker_role_apt_cache_valid_time }}"
with_items:
- name: linux-image-generic-lts-trusty
version: "12.04"
- name: linux-headers-generic-lts-trusty
version: "12.04"
- name: linux-image-generic-lts-xenial
version: "14.04"
register: kernel_result
when: ansible_distribution_version == item.version

- name: Install latest kernel extras for Ubuntu 13.04, 13.10
apt:
pkg: "linux-image-extra-{{ ansible_kernel }}"
state: "{{ kernel_pkg_state }}"
update_cache: yes
cache_valid_time: "{{ docker_role_apt_cache_valid_time }}"
when: ansible_distribution_version in ['13.04', '13.10']

# Fix for https://github.com/dotcloud/docker/issues/4568
- name: Install cgroup-lite for Ubuntu 13.10
apt:
pkg: cgroup-lite
state: "{{ cgroup_lite_pkg_state }}"
update_cache: yes
cache_valid_time: "{{ docker_role_apt_cache_valid_time }}"
register: cgroup_lite_result
when: ansible_distribution_version == '13.10'

- include: reboot-and-wait.yml

# Newer versions of Docker no longer require apparmor, but it seems like a good thing to have.
- name: Install apparmor
apt: pkg=apparmor state=present

# Newer documentation suggests installing a few other (non kernel) packages
# https://github.com/docker/docker.github.io/blob/9093e0a/engine/installation/linux/ubuntu.md#recommended-extra-packages
# https://github.com/docker/docker.github.io/blob/9093e0a/engine/installation/linux/ubuntu.md#set-up-the-repository
- name: Install a few recommended packages
apt: pkg="{{ item }}" state=present
with_items:
- curl
- apt-transport-https
- ca-certificates

- name: Write /etc/default/docker config file
template: src=etc_default_docker.j2 dest=/etc/default/docker
register: r_etc_default_docker
Expand All @@ -73,23 +46,20 @@
# if we changed the config, but didn't reinstall docker, then restart it
- name: Restart docker on config change
service: name=docker state=restarted
when: r_etc_default_docker|changed and not r_docker_package_install|changed
when: r_etc_default_docker|changed and not r_docker_package_install|changed and not check_mode

- name: Ensure that Docker is running
service: name="docker" state=started
when: not check_mode

- name: Wait until docker daemon is available
command: docker info
register: r_docker_info
# need a special case here, or this always fails in check mode.
until: r_docker_info|skipped or r_docker_info.rc == 0
retries: "{{ docker_daemon_startup_timeout_sec }}"
retries: "{{ docker_daemon_startup_retries }}"
delay: 1

- name: reread docker facts
setup: filter=ansible_docker0
when: r_etc_default_docker|changed or r_docker_package_install|changed

- name: Check if /etc/default/ufw exists
stat: path=/etc/default/ufw
register: ufw_default_exists
Expand All @@ -100,3 +70,8 @@
regexp: "^DEFAULT_FORWARD_POLICY="
line: "DEFAULT_FORWARD_POLICY=\"ACCEPT\""
when: ufw_default_exists.stat.exists

# this role modifies the host in ways which might have been cached
# let's update all facts here to be sure we have ansible up to date.
- name: update facts about host
setup:
27 changes: 0 additions & 27 deletions tasks/reboot-and-wait.yml

This file was deleted.

25 changes: 24 additions & 1 deletion tests/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Here are some playbooks that support different tests, and some code to support r
them in Vagrant.

## Running tests

The tests are written as Ansible playbooks that operate on `hosts: all`. The tests don't
assume much about the machine they're operating on, but it should be a clean machine if
possible.
Expand All @@ -17,4 +18,26 @@ To run all tests:

To run a specific test:

TESTS=upgrade ./run_tests.sh
TESTS=new_install ./run_tests.sh

## Testing on vagrant

If you have issues with restarting vagrant boxes due to mounting issues you might need
to check your virtualbox and vagrant versions are up to date. If that doesn't solve the
issue you could also check your vagrant plugins.

> vagrant plugin list
vagrant-cachier (1.2.1)
vagrant-hostmanager (1.8.5)
vagrant-multiprovider-snap (0.0.14)
vagrant-share (1.1.6, system)
vagrant-vbguest (0.13.0)

To prevent having to enter your password for hostmanager configure passwordless sudo:

* https://github.com/devopsgroup-io/vagrant-hostmanager#passwordless-sudo

## Ubuntu versions

If you have a particular version of Ubuntu you need to test with modify the Vagrantfile to
load a box with the version you need to test before running the test script.
Loading

0 comments on commit 2a3155f

Please sign in to comment.