Skip to content
This repository has been archived by the owner on Apr 19, 2019. It is now read-only.

safe upgrade is upgrading the kernel #92

Closed
cloudnull opened this issue Sep 9, 2014 · 14 comments · Fixed by #97
Closed

safe upgrade is upgrading the kernel #92

cloudnull opened this issue Sep 9, 2014 · 14 comments · Fixed by #97

Comments

@cloudnull
Copy link
Contributor

When the setup-common role runs a safe-upgrade is run to ensure all of the packages that are determined to be safely upgradable are up-to-date. Sadly the ansible apt module uses aptitude to perform this upgrade which attempts to bring in new kernels as they become available. Presently we are dep'ing on kernel 3.13.0-34-generic and the new stable kernel for Ubuntu 14.04.01 kernel 3.13.0-35-generic. It would seem that this is going to be a never ending battle of incremental kernel releases. If we are not going to be deploying a repository of frozen packages at this time we may need change the kernel check to set on the version and allow for kernel releases of >= 34.

andymcc added a commit to andymcc/ansible-lxc-rpc that referenced this issue Sep 9, 2014
Snce we aren't providing kernel packages having a set kernel version
will constantly need updating.
Set a minimum required version and ensure the kernel we use is newer
than this version.

Fixes rcbops#92
@byronmccollum
Copy link

Instead of running uname -r, the same value is in the ansible_kernel fact.

Additionally, is this just doing a string comparison? Maybe something like this...?

---
# This playbook checks kernel version

- name: Check Kernel Version
  hosts: all
  gather_facts: yes
  vars:
    required_kernel_version: '3.13.0'
    required_kernel_patch: '34'
    required_kernel_variant: 'generic'
  tasks:
    - name: Get Kernel Parts
      set_fact:
        kernel_version: "{{ ansible_kernel.split('-')[0] }}"
        kernel_patch: "{{ ansible_kernel.split('-')[1] }}"
        kernel_variant: "{{ ansible_kernel.split('-')[2] }}"

    - name: Check Kernel Version
      fail:
        msg: >
          Wrong kernel Version found
          [ {{ ansible_kernel }} < {{ [required_kernel_version, required_kernel_patch, required_kernel_variant]|join('-') }} ]
          Resolve this issue before continuing.
      when: kernel_version | version_compare(required_kernel_version, '<') or kernel_patch | version_compare(required_kernel_patch, '<') or kernel_variant != required_kernel_variant

@byronmccollum
Copy link

That fail...when won't work when the kernel revs to 3.14.0-0-generic. Stupid version numbers.

Breaking into three separate checks:

    - name: Check Kernel Version
      fail:
        msg: >
          Wrong kernel Version found
          [ {{ ansible_kernel }} < {{ [required_kernel_version, required_kernel_patch, required_kernel_variant]|join('-') }} ]
          Resolve this issue before continuing.
      when: kernel_version | version_compare(required_kernel_version, '<')

    - name: Check Kernel Patch
      fail:
        msg: >
          Wrong kernel Version found
          [ {{ ansible_kernel }} < {{ [required_kernel_version, required_kernel_patch, required_kernel_variant]|join('-') }} ]
          Resolve this issue before continuing.
      when: kernel_patch | version_compare(required_kernel_patch, '<')

    - name: Check Kernel Variant
      fail:
        msg: >
          Wrong kernel Version found
          [ {{ ansible_kernel }} < {{ [required_kernel_version, required_kernel_patch, required_kernel_variant]|join('-') }} ]
          Resolve this issue before continuing.
      when: kernel_variant != required_kernel_variant

andymcc added a commit to andymcc/ansible-lxc-rpc that referenced this issue Sep 9, 2014
Snce we aren't providing kernel packages having a set kernel version
will constantly need updating.
Set a minimum required version and ensure the kernel we use is newer
than this version.

Fixes rcbops#92
@andymcc
Copy link
Contributor

andymcc commented Sep 9, 2014

@byronmccollum any reason we have to check all 3 individually?
If we just do a ">" check it seems to do that for you.
Adjusted to use the ansible_kernel fact though - saves on the "uname -r"

@byronmccollum
Copy link

If it's a string compare...wouldn't 3.13.34 be less than 3.4.34 ?

@andymcc
Copy link
Contributor

andymcc commented Sep 9, 2014

ahh true. it seems really inefficient to have to make 3 checks for 1 simple check though.

@byronmccollum
Copy link

Well, you need to check if kernel_version > required_kernel_version, and if so, you really don't care about kernel_patch.

But when kernel_version == required_kernel_version, then you need to check the kernel_patch.

@Apsu
Copy link
Contributor

Apsu commented Sep 9, 2014

http://docs.ansible.com/playbooks_variables.html#version-comparison-filters is what we really want; this is common enough it's already been solved with a single comparison filter.

@byronmccollum
Copy link

version_compare trips up on the variant. Unless you don't care about that.

@Apsu
Copy link
Contributor

Apsu commented Sep 9, 2014

>>> from distutils.version import LooseVersion
>>> LooseVersion("3.13.0-34") < LooseVersion("3.13.0-36")
True
>>> LooseVersion("3.13.0-12") < LooseVersion("3.13.0-2")
False
>>> LooseVersion("3.13.0-2") < LooseVersion("3.13.0-12")
True
>>> LooseVersion("3.13.0-2-generic") < LooseVersion("3.13.0-12-generic")
True
>>> LooseVersion("3.13.0-2-generic") < LooseVersion("3.13.0-1-generic")
False
>>> LooseVersion("3.13.0-2-generic") < LooseVersion("3.4.0-1-generic")
False

Variants don't break the loose version_compare (which uses distutils.version.LooseVersion, according to this: https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/filter_plugins/core.py#L30), and IMO we definitely don't care about comparing variants because A) versioning across variants makes no sense, they're different types of kernels, and B) I can't imagine we have any interest whatsoever in using !generic Ubuntu kernels.

So I say use the version_compare filter without strict=True and call it a job welld one.

@byronmccollum
Copy link

Well hot damn. Problem solved.

@andymcc
Copy link
Contributor

andymcc commented Sep 9, 2014

You could recreate and pad out with 0's up to 3chars using zfill - ensuring that 014 > 004 in a string comparison, but thats probably more effort than its worth. I can't think of another sensible way to do this, do you want to make a PR against master with this changed to do the 3 checks.

@byronmccollum
Copy link

as pointed out by @Apsu...

when: ansible_kernel | version_compare(required_kernel, '<')

...should do the trick.

@byronmccollum
Copy link

I still feel like it needs to account for the variant in some manner.

@Apsu, do you think that it should also fail if the kernel is not generic?

@byronmccollum
Copy link

PR #100

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants