0

I have hit an issue when upgrading my code (written for 3.x) to live happily on our new 5.x puppet environment .. My question is specifically related to 'question mark conditionals' (not sure how else to describe them) ..

In the snippet below I have verified that the facter variable $operatingsystemmajrelease does resolve to 6 .. In version 3.x of puppet and below .. the 'notify' i have added at the end would return "six" (as expected).. but in puppet 4.x and above.. it drops down to the default "dont know" (therefore the comparison operator is not matching) ..I believe it has something to do with facter returning the value as a string , and I know puppet 4.x is a lot stricter with strings.. Ive tried quoting the conditionals '5', '6' etc ...but no joy ..does anyone know how I get around this to make this conditional work properly

  $version = $operatingsystemmajrelease ? {
    5                 => 'five',
    6                 => 'six',
    7                 => 'seven',
    default           => 'dont know'
  }

  notify {"version  is $version":}

1 Answer 1

0

That fact is a string, which you can prove with:

notice("${type($operatingsystemmajrelease)}")

Which will return:

Notice: Scope(Class[main]): String

So even though it looks numeric, it should be:

$version = $operatingsystemmajrelease ? {
  '5'     => 'five',
  '6'     => 'six',
  '7'     => 'seven',
  default => "don't know",
}

If you want it to be a real integer for the purposes of using </> operators you can always do:

$version = Integer($operatingsystemmajrelease)
notice("${version} is of type ${type($version)}")

Which gives you:

Notice: Scope(Class[main]): 7 is of type Integer[7, 7]

etc. however there's also the versioncmp() function specifically for comparing version numbers. There's also the newer structured facts so you probably want to use $facts['os']['release']['major'], (which also happens to be a string).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .