Checking the input value with a validate block

We can validate the provided value of a new property called version with a validate block and, for example, a regex expression, as shown in the following code:

Puppet::Type.newtype(:mynewtype) do   ...   newproperty(:version) do     validate do |value|       fail("Invalid version specified") unless value =~         /^(\d+\.)?(\d+\.)?(\*|\d+)$/     end   end   ... end

Get Mastering Puppet 5 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.