Code Monkey home page Code Monkey logo

Comments (14)

byronmccollum avatar byronmccollum commented on July 21, 2024

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

from ansible-lxc-rpc.

byronmccollum avatar byronmccollum commented on July 21, 2024

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

from ansible-lxc-rpc.

andymcc avatar andymcc commented on July 21, 2024

@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"

from ansible-lxc-rpc.

byronmccollum avatar byronmccollum commented on July 21, 2024

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

from ansible-lxc-rpc.

andymcc avatar andymcc commented on July 21, 2024

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

from ansible-lxc-rpc.

byronmccollum avatar byronmccollum commented on July 21, 2024

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.

from ansible-lxc-rpc.

Apsu avatar Apsu commented on July 21, 2024

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.

from ansible-lxc-rpc.

byronmccollum avatar byronmccollum commented on July 21, 2024

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

from ansible-lxc-rpc.

Apsu avatar Apsu commented on July 21, 2024
>>> 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.

from ansible-lxc-rpc.

byronmccollum avatar byronmccollum commented on July 21, 2024

Well hot damn. Problem solved.

from ansible-lxc-rpc.

andymcc avatar andymcc commented on July 21, 2024

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.

from ansible-lxc-rpc.

byronmccollum avatar byronmccollum commented on July 21, 2024

as pointed out by @Apsu...

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

...should do the trick.

from ansible-lxc-rpc.

byronmccollum avatar byronmccollum commented on July 21, 2024

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?

from ansible-lxc-rpc.

byronmccollum avatar byronmccollum commented on July 21, 2024

PR #100

from ansible-lxc-rpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.