Puppet Function: debian::codename::compare

Defined in:
modules/debian/functions/codename/compare.pp
Function type:
Puppet Language

Overview

debian::codename::compare(String $codename, Enum['==', '>=', '>', '<', '<=', '!='] $operator = '==')Boolean

Examples:

Assuming theses functions are compiled for a host running debian buster then

debian::codename::compare('buster') == True
debian::codename::compare('stretch') == False
debian::codename::compare('stretch', '<') == False
debian::codename::compare('stretch', '>') == True
debian::codename::compare('buster', '>=') == True
debian::codename::compare('buster', '<=') == True

Parameters:

  • codename (String)

    the codename you want to test against

  • operator (Enum['==', '>=', '>', '<', '<=', '!=']) (defaults to: '==')

    the comparison operator to use

Returns:

  • (Boolean)

    result of the comparison



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'modules/debian/functions/codename/compare.pp', line 12

function debian::codename::compare (
    String                                 $codename,
    Enum['==', '>=', '>', '<', '<=', '!='] $operator = '==',
) >> Boolean {
    include debian

    $valid_codenames = $debian::supported[$facts['os']['name']]

    unless $codename in $valid_codenames {
        fail("invalid codename (${codename}). supported codenames : ${valid_codenames.keys.join(', ')}")
    }

    $operator ? {
        '>='    => Integer($facts['os']['release']['major']) >= $valid_codenames[$codename],
        '>'     => Integer($facts['os']['release']['major']) > $valid_codenames[$codename],
        '<='    => Integer($facts['os']['release']['major']) <= $valid_codenames[$codename],
        '<'     => Integer($facts['os']['release']['major']) < $valid_codenames[$codename],
        '!='    => Integer($facts['os']['release']['major']) != $valid_codenames[$codename],
        default => Integer($facts['os']['release']['major']) == $valid_codenames[$codename],
    }
}