Project

General

Profile

Actions

Enhancement #26320

open

Enrich node.inventory[os] json property with more information

Added by Michel BOUISSOU 17 days ago. Updated 10 days ago.

Status:
New
Priority:
4
Assignee:
-
Category:
-
Target version:
UX impact:
Suggestion strength:
Want - This would make my life a lot easier but I can manage without
User visibility:
Effort required:
Name check:
To do
Fix check:
To do
Regression:
No

Description

Rationale :

The node.inventory[os] json property carries a number of keys that can be useful in directives and techniques.

However it misses some values that may be needed in directives and techniques, i.e. for building proper RH or Debian/Ubuntu repository files.

These values are not always immediately parseable from /etc/os-release and need playing i.e. with awk, or may be available thru lsb_release however lsb_release is not systematically available on every Linux node.
The needed values in node.inventory[os] would be :

- For RedHat family (would nicely be present for all Linux distros anyway) :

- "major_version": "9"
- Rationale :
- The current implementation only shows the complete version string, but only the numerical major version may be needed
- It is not directly present in /etc/os-release and needs to be parsed

- For Debian/Ubuntu families :

- "version_codename": "bullseye"
- Rationale :
- The current implementation only shows the complete version string, but only the version codename may be needed
- It is not directly present in /etc/os-release and needs to be parsed

Sample implementation in awk, producing a suitable enriched JSON (with a few more fields) :

#!/bin/sh

# Outputs Linux version information JSON by parsing /etc/os-release
#
# Especially for case where we will need
# - Debian/Ubuntu version codename
# - RH family major version

awk -F= '
BEGIN {
    print "{\n  \"linux_version\": {";
    sep="    " 
}
/^(NAME|PRETTY_NAME|ID(_LIKE)?|BUILD_ID|VERSION|(VERSION|UBUNTU)_CODENAME|PLATFORM_ID)=/ {
    gsub(/"/, "", $2);
    key = tolower($1);
    printf "%s\"%s\": \"%s\"", sep, key, $2;
    sep = ",\n    " 

    if (key == "version") {
        if (match($2, /^[0-9]+/)) {
            major_version = substr($2, RSTART, RLENGTH);
        }
    }
}
END {
    if (major_version != "") {
        printf ",\n    \"major_version\": \"%s\"", major_version;
    }
    print "\n  }\n}" 
}' /etc/os-release

Example outputs in Debian / Ubuntu :

{
  "linux_version": {
    "pretty_name": "Debian GNU/Linux 11 (bullseye)",
    "name": "Debian GNU/Linux",
    "version": "11 (bullseye)",
    "version_codename": "bullseye",
    "id": "debian",
    "major_version": "11" 
  }
}
{
  "linux_version": {
    "name": "Ubuntu",
    "version": "20.04.6 LTS (Focal Fossa)",
    "id": "ubuntu",
    "id_like": "debian",
    "pretty_name": "Ubuntu 20.04.6 LTS",
    "version_codename": "focal",
    "ubuntu_codename": "focal",
    "major_version": "20" 
  }
}

Example output in RH :

{
  "linux_version": {
    "name": "AlmaLinux",
    "version": "9.3 (Shamrock Pampas Cat)",
    "id": "almalinux",
    "id_like": "rhel centos fedora",
    "platform_id": "platform:el9",
    "pretty_name": "AlmaLinux 9.3 (Shamrock Pampas Cat)",
    "major_version": "9" 
  }
}
Actions

Also available in: Atom PDF