From cd15b9e80207fc200369af8ffbc7b4a90bea15e9 Mon Sep 17 00:00:00 2001 From: Dave Charness Date: Fri, 16 Dec 2016 11:55:58 -0800 Subject: [PATCH 1/6] Upgrade 14.04 to xenial kernel Extend the 12.04 -> trusty kernel upgrade to the comparable (hardware enablement) upgrade of 14.04 -> xenial linux-image-generic-lts-xenial depends on the corresponding kernel-extra package, so limit that task to 13.xx distros only. --- tasks/main.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index b4c15eb..6f9dd94 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,25 +11,29 @@ when: docker_version is not defined # https://docs.docker.com/installation/ubuntulinux/ -- name: Install trusty kernel onto 12.04 +- name: Install backported kernel on pre-16.04 LTS apt: - pkg: "{{ item }}" + pkg: "{{ item.name }}" state: latest update_cache: yes cache_valid_time: "{{ docker_role_apt_cache_valid_time }}" with_items: - - linux-image-generic-lts-trusty - - linux-headers-generic-lts-trusty + - 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 == '12.04' + when: ansible_distribution_version == item.version -- name: Install latest kernel extras for Ubuntu 13.04+ +- 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 != '12.04' + 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 From 706a0325d78494eef286888380596278f984180b Mon Sep 17 00:00:00 2001 From: Dave Charness Date: Fri, 16 Dec 2016 12:13:16 -0800 Subject: [PATCH 2/6] Factor out reboot logic In preparation for properly supporting vagrant reboots, factor out the reboot logic into its own file. The logic could be useful elsewhere, and this also abstracts the concept out of the way of the real job of upgrading. --- tasks/main.yml | 21 +++++---------------- tasks/reboot-and-wait.yml | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 tasks/reboot-and-wait.yml diff --git a/tasks/main.yml b/tasks/main.yml index 6f9dd94..b82af29 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -45,22 +45,11 @@ register: cgroup_lite_result when: ansible_distribution_version == '13.10' -- name: Reboot instance - command: /sbin/shutdown -r now - register: reboot_result - when: "(ansible_distribution_version == '12.04' and kernel_result|changed) - or (ansible_distribution_version == '13.10' and cgroup_lite_result|changed)" - -- name: Wait for instance to come online - local_action: - module: wait_for - host: "{{ ansible_ssh_host|default(inventory_hostname) }}" - port: "{{ ansible_ssh_port|default(ssh_port) }}" - delay: 30 - timeout: 600 - state: started - when: "(ansible_distribution_version == '12.04' and reboot_result|changed) - or (ansible_distribution_version == '13.10' and cgroup_lite_result|changed)" +- name: Is reboot necessary? + set_fact: + reboot_needed: "{{(kernel_result or cgroup_lite_result or {'changed': False}) | changed}}" + +- 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 diff --git a/tasks/reboot-and-wait.yml b/tasks/reboot-and-wait.yml new file mode 100644 index 0000000..24cec60 --- /dev/null +++ b/tasks/reboot-and-wait.yml @@ -0,0 +1,18 @@ +--- +# reboot an Ubuntu machine if needed and wait for it to come back +- name: Reboot instance + command: /sbin/shutdown -r now + register: reboot_result + when: reboot_needed + +- name: Wait for instance to come online + local_action: + module: wait_for + host: "{{ ansible_ssh_host|default(inventory_hostname) }}" + port: "{{ ansible_ssh_port|default(ssh_port) }}" + delay: 30 + timeout: 600 + state: started + when: reboot_result|changed + become: false + From 0958d6d6425c44d1a4e6b96cdec3179ce2088bee Mon Sep 17 00:00:00 2001 From: Dave Charness Date: Fri, 16 Dec 2016 12:15:30 -0800 Subject: [PATCH 3/6] Use vagrant reload for rebooting a vagrant instance Rebooting the instance from the machine itself bypasses setup that `vagrant up' does, such as synchronized folders. This breaks, at least, package installation with the vagrant-cachier plugin, as its overlay directory won't be mounted. Use ansible_ssh_user == 'vagrant' as the signal that a machine is a vagrant instance. --- tasks/reboot-and-wait.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tasks/reboot-and-wait.yml b/tasks/reboot-and-wait.yml index 24cec60..83b09ae 100644 --- a/tasks/reboot-and-wait.yml +++ b/tasks/reboot-and-wait.yml @@ -3,7 +3,17 @@ - name: Reboot instance command: /sbin/shutdown -r now register: reboot_result - when: reboot_needed + when: + - reboot_needed + - ansible_ssh_user != 'vagrant' + +- name: Reboot vagrant instance + local_action: command vagrant reload "{{inventory_hostname}}" + register: reboot_result + when: + - reboot_needed + - ansible_ssh_user == 'vagrant' + become: false - name: Wait for instance to come online local_action: From 8e3d33562cc027606eb25080521ec5e0ffc49173 Mon Sep 17 00:00:00 2001 From: Dave Charness Date: Fri, 16 Dec 2016 12:46:26 -0800 Subject: [PATCH 4/6] Centralize vagrant detection - Don't repeat yourself - Allow explicit setting of `is_vagrant' to override the detection, e.g., to support a user other than vagrant on a vagrant instance --- tasks/reboot-and-wait.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tasks/reboot-and-wait.yml b/tasks/reboot-and-wait.yml index 83b09ae..ce17140 100644 --- a/tasks/reboot-and-wait.yml +++ b/tasks/reboot-and-wait.yml @@ -1,18 +1,22 @@ --- # reboot an Ubuntu machine if needed and wait for it to come back +- name: Detect vagrant instance + set_fact: + is_vagrant: "{{is_vagrant | default(ansible_ssh_user == 'vagrant')}}" + - name: Reboot instance command: /sbin/shutdown -r now register: reboot_result when: - reboot_needed - - ansible_ssh_user != 'vagrant' + - not is_vagrant - name: Reboot vagrant instance local_action: command vagrant reload "{{inventory_hostname}}" register: reboot_result when: - reboot_needed - - ansible_ssh_user == 'vagrant' + - is_vagrant become: false - name: Wait for instance to come online From b90e21c74f5cea65bda9d91ad06e9fdd6c9031f9 Mon Sep 17 00:00:00 2001 From: Dave Charness Date: Fri, 16 Dec 2016 13:44:25 -0800 Subject: [PATCH 5/6] Trust packages for whether reboot is necessary Installing a kernel package on Ubuntu creates a /var/run/reboot-required file. Key off its existence instead of trying to figure out ourselves whether to reboot. The `removes' argument to `command' handles conditioning the reboot on whether the file exists. For a vagrant instance, fire a `vagrant reload' after rebooting from on the machine so we still get the setup `vagrant up' does. --- tasks/main.yml | 4 ---- tasks/reboot-and-wait.yml | 13 ++++--------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index b82af29..6de1cd7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -45,10 +45,6 @@ register: cgroup_lite_result when: ansible_distribution_version == '13.10' -- name: Is reboot necessary? - set_fact: - reboot_needed: "{{(kernel_result or cgroup_lite_result or {'changed': False}) | changed}}" - - include: reboot-and-wait.yml # Newer versions of Docker no longer require apparmor, but it seems like a good thing to have. diff --git a/tasks/reboot-and-wait.yml b/tasks/reboot-and-wait.yml index ce17140..a554066 100644 --- a/tasks/reboot-and-wait.yml +++ b/tasks/reboot-and-wait.yml @@ -6,17 +6,13 @@ - name: Reboot instance command: /sbin/shutdown -r now + args: + removes: /var/run/reboot-required register: reboot_result - when: - - reboot_needed - - not is_vagrant -- name: Reboot vagrant instance +- name: Reload vagrant instance local_action: command vagrant reload "{{inventory_hostname}}" - register: reboot_result - when: - - reboot_needed - - is_vagrant + when: reboot_result|changed and is_vagrant become: false - name: Wait for instance to come online @@ -29,4 +25,3 @@ state: started when: reboot_result|changed become: false - From 5647f16584f03fae24bb7f5cfc8d224d70a629c9 Mon Sep 17 00:00:00 2001 From: Dave Charness Date: Wed, 4 Jan 2017 14:02:32 -0800 Subject: [PATCH 6/6] Expand comment on kernel upgrade - Add to the comment some information on why we're upgrading - Update the link for docker's redirect and to point to a more specific fragment of the doc --- tasks/main.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 6de1cd7..0889b73 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -10,8 +10,15 @@ fail: msg="Required variable \"docker_version\" is not defined." when: docker_version is not defined -# https://docs.docker.com/installation/ubuntulinux/ -- name: Install backported kernel on pre-16.04 LTS +# 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