Comparing package versions

Package version numbers are odd things. They look like decimal numbers, but they're not —a version number is often in the form 2.6.4, for example. If you need to compare one version number with another, you can't do a straightforward string comparison: 2.6.4 would be interpreted as greater than 2.6.12. A numeric comparison won't work because they're not valid numbers.

Puppet's versioncmp function comes to the rescue. If you pass it two things that look like version numbers, it will compare them and return a value indicating which is the greater:

versioncmp( A, B )

returns the following:

  • 0 if A and B are equal
  • Greater than 1 if A is higher than B
  • Less than 0 if A is less than B

How to do it…

  1. Add the following to your manifest: ...

Get Puppet 2.7 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.