diff --git a/tasks/main.yml b/tasks/main.yml index b4c15eb..0889b73 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -10,26 +10,37 @@ fail: msg="Required variable \"docker_version\" is not defined." when: docker_version is not defined -# https://docs.docker.com/installation/ubuntulinux/ -- name: Install trusty kernel onto 12.04 +# 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 }}" + 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 @@ -41,22 +52,7 @@ 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)" +- 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..a554066 --- /dev/null +++ b/tasks/reboot-and-wait.yml @@ -0,0 +1,27 @@ +--- +# 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 + args: + removes: /var/run/reboot-required + register: reboot_result + +- name: Reload vagrant instance + local_action: command vagrant reload "{{inventory_hostname}}" + when: reboot_result|changed and is_vagrant + become: false + +- 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